@@ -32,6 +32,16 @@ auto_ismaster (mock_server_t *server,
32
32
bson_free (response );
33
33
}
34
34
35
+
36
+ int
37
+ should_run_fam_wc (void )
38
+ {
39
+ if (test_framework_is_replset ()) {
40
+ return test_framework_max_wire_version_at_least (WIRE_VERSION_FAM_WRITE_CONCERN );
41
+ }
42
+ return 0 ;
43
+ }
44
+
35
45
static mongoc_collection_t *
36
46
get_test_collection (mongoc_client_t * client ,
37
47
const char * prefix )
@@ -211,6 +221,59 @@ test_find_and_modify_write_concern (int wire_version)
211
221
bson_destroy (& doc );
212
222
}
213
223
224
+ static void
225
+ test_find_and_modify_write_concern_wire_32_failure (void * context )
226
+ {
227
+ mongoc_collection_t * collection ;
228
+ mongoc_client_t * client ;
229
+ bson_error_t error ;
230
+ mongoc_find_and_modify_opts_t * opts ;
231
+ bson_t reply ;
232
+ bson_t query = BSON_INITIALIZER ;
233
+ bson_t * update ;
234
+ bool success ;
235
+ mongoc_write_concern_t * wc ;
236
+
237
+ client = test_framework_client_new ();
238
+ collection = get_test_collection (client , "writeFailure" );
239
+ wc = mongoc_write_concern_new ();
240
+
241
+ mongoc_write_concern_set_w (wc , 42 );
242
+ mongoc_collection_set_write_concern (collection , wc );
243
+
244
+ /* Find Zlatan Ibrahimovic, the striker */
245
+ BSON_APPEND_UTF8 (& query , "firstname" , "Zlatan" );
246
+ BSON_APPEND_UTF8 (& query , "lastname" , "Ibrahimovic" );
247
+ BSON_APPEND_UTF8 (& query , "profession" , "Football player" );
248
+ BSON_APPEND_INT32 (& query , "age" , 34 );
249
+ BSON_APPEND_INT32 (& query , "goals" , (16 + 35 + 23 + 57 + 16 + 14 + 28 + 84 )+ (1 + 6 + 62 ));
250
+
251
+ /* Add his football position */
252
+ update = BCON_NEW ("$set" , "{" ,
253
+ "position" , BCON_UTF8 ("striker" ),
254
+ "}" );
255
+
256
+ opts = mongoc_find_and_modify_opts_new ();
257
+
258
+ mongoc_find_and_modify_opts_set_update (opts , update );
259
+
260
+ /* Create the document if it didn't exist, and return the updated document */
261
+ mongoc_find_and_modify_opts_set_flags (opts , MONGOC_FIND_AND_MODIFY_UPSERT |MONGOC_FIND_AND_MODIFY_RETURN_NEW );
262
+
263
+ success = mongoc_collection_find_and_modify_with_opts (collection , & query , opts , & reply , & error );
264
+
265
+ ASSERT (success );
266
+ ASSERT_ERROR_CONTAINS (error , MONGOC_ERROR_WRITE_CONCERN , 100 , "Write Concern error:" );
267
+
268
+ bson_destroy (& reply );
269
+ bson_destroy (update );
270
+ bson_destroy (& query );
271
+ mongoc_find_and_modify_opts_destroy (opts );
272
+ mongoc_collection_drop (collection , NULL );
273
+ mongoc_collection_destroy (collection );
274
+ mongoc_client_destroy (client );
275
+ }
276
+
214
277
static void
215
278
test_find_and_modify_write_concern_wire_32 (void )
216
279
{
@@ -303,4 +366,7 @@ test_find_and_modify_install (TestSuite *suite)
303
366
test_find_and_modify_write_concern_wire_32 );
304
367
TestSuite_Add (suite , "/find_and_modify/find_and_modify/write_concern_pre_32" ,
305
368
test_find_and_modify_write_concern_wire_pre_32 );
369
+ TestSuite_AddFull (suite , "/find_and_modify/find_and_modify/write_concern_failure" ,
370
+ test_find_and_modify_write_concern_wire_32_failure , NULL , NULL ,
371
+ should_run_fam_wc );
306
372
}
0 commit comments