Skip to content

Commit 9b391f8

Browse files
authored
CDRIVER-4539 wait for unacknowledged writes to apply in test_bulk_reply_w0 (#1170)
* remove incorrect comment * wait for unacknowledge writes to apply in test_bulk_reply_w0 * use appName to isolate failpoint
1 parent 218445d commit 9b391f8

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

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

Lines changed: 30 additions & 7 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);
@@ -4947,6 +4969,7 @@ test_bulk_write_multiple_errors (void *unused)
49474969

49484970
client = test_framework_new_default_client ();
49494971
BSON_ASSERT (client);
4972+
mongoc_client_set_appname (client, "test_bulk_write_multiple_errors");
49504973

49514974
collection = get_test_collection (client, "test_bulk_write_multiple_errors");
49524975
BSON_ASSERT (collection);
@@ -4955,15 +4978,13 @@ test_bulk_write_multiple_errors (void *unused)
49554978
// the first error.
49564979
bson_append_bool (&opts, "ordered", 7, false);
49574980
bulk = mongoc_collection_create_bulk_operation_with_opts (collection, &opts);
4958-
// Insert three documents. This is sent as one "insert" command to the
4959-
// server.
4960-
// configure fail point
4981+
// Use appName to isolate the failpoint to this test.
49614982
bool ret = mongoc_client_command_simple (
49624983
client,
49634984
"admin",
4964-
tmp_bson (
4965-
"{'configureFailPoint': 'failCommand', 'mode': {'times': 2}, "
4966-
"'data': {'failCommands': ['insert', 'delete'], 'errorCode': 8}}"),
4985+
tmp_bson ("{'configureFailPoint': 'failCommand', 'mode': {'times': 2}, "
4986+
"'data': {'failCommands': ['insert', 'delete'], 'errorCode': "
4987+
"8, 'appName': 'test_bulk_write_multiple_errors'}}"),
49674988
NULL,
49684989
NULL,
49694990
&error);
@@ -5307,5 +5328,7 @@ test_bulk_install (TestSuite *suite)
53075328
test_bulk_write_multiple_errors,
53085329
NULL,
53095330
NULL,
5310-
test_framework_skip_if_no_failpoint);
5331+
test_framework_skip_if_no_failpoint,
5332+
/* Require server 4.2 for failCommand appName */
5333+
test_framework_skip_if_max_wire_version_less_than_8);
53115334
}

0 commit comments

Comments
 (0)