Skip to content

Commit 24c6f63

Browse files
committed
wait for unacknowledge writes to apply in test_bulk_reply_w0
1 parent b36fdfd commit 24c6f63

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/libmongoc/tests/test-mongoc-bulk.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,6 +4211,22 @@ test_hint_pooled_command_primary (void)
42114211
_test_bulk_hint (true, true);
42124212
}
42134213

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+
}
42144230

42154231
static void
42164232
test_bulk_reply_w0 (void)
@@ -4233,12 +4249,18 @@ test_bulk_reply_w0 (void)
42334249
mongoc_bulk_operation_update (
42344250
bulk, tmp_bson ("{}"), tmp_bson ("{'$set': {'x': 1}}"), false);
42354251
mongoc_bulk_operation_remove (bulk, tmp_bson ("{}"));
4252+
mongoc_bulk_operation_insert (bulk, tmp_bson ("{'finished': true}"));
42364253

42374254
ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, &reply, &error),
42384255
error);
42394256

42404257
ASSERT (bson_empty (&reply));
42414258

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+
42424264
bson_destroy (&reply);
42434265
mongoc_bulk_operation_destroy (bulk);
42444266
bson_destroy (&opts);

0 commit comments

Comments
 (0)