@@ -4211,6 +4211,22 @@ test_hint_pooled_command_primary (void)
4211
4211
_test_bulk_hint (true, true);
4212
4212
}
4213
4213
4214
+ // test_bulk_reply_w0_finished returns true when the last unacknowledged write
4215
+ // has applied in test_bulk_reply_w0.
4216
+ static bool
4217
+ test_bulk_reply_w0_finished (mongoc_collection_t * coll )
4218
+ {
4219
+ bson_error_t error ;
4220
+ int64_t count =
4221
+ mongoc_collection_count_documents (coll ,
4222
+ tmp_bson ("{'finished': true}" ),
4223
+ NULL /* opts */ ,
4224
+ NULL /* read_prefs */ ,
4225
+ NULL /* reply */ ,
4226
+ & error );
4227
+ ASSERT_OR_PRINT (-1 != count , error );
4228
+ return count == 1 ;
4229
+ }
4214
4230
4215
4231
static void
4216
4232
test_bulk_reply_w0 (void )
@@ -4233,12 +4249,18 @@ test_bulk_reply_w0 (void)
4233
4249
mongoc_bulk_operation_update (
4234
4250
bulk , tmp_bson ("{}" ), tmp_bson ("{'$set': {'x': 1}}" ), false);
4235
4251
mongoc_bulk_operation_remove (bulk , tmp_bson ("{}" ));
4252
+ mongoc_bulk_operation_insert (bulk , tmp_bson ("{'finished': true}" ));
4236
4253
4237
4254
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk , & reply , & error ),
4238
4255
error );
4239
4256
4240
4257
ASSERT (bson_empty (& reply ));
4241
4258
4259
+ // Wait for the last insert to finish applying before proceeding to the next
4260
+ // test. Otherwise, the commands may trigger failpoints of other tests (see
4261
+ // CDRIVER-4539).
4262
+ WAIT_UNTIL (test_bulk_reply_w0_finished (collection ));
4263
+
4242
4264
bson_destroy (& reply );
4243
4265
mongoc_bulk_operation_destroy (bulk );
4244
4266
bson_destroy (& opts );
0 commit comments