Skip to content

CDRIVER-4539 wait for unacknowledged writes to apply in test_bulk_reply_w0 #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions src/libmongoc/tests/test-mongoc-bulk.c
Original file line number Diff line number Diff line change
Expand Up @@ -4211,6 +4211,22 @@ test_hint_pooled_command_primary (void)
_test_bulk_hint (true, true);
}

// test_bulk_reply_w0_finished returns true when the last unacknowledged write
// has applied in test_bulk_reply_w0.
static bool
test_bulk_reply_w0_finished (mongoc_collection_t *coll)
{
bson_error_t error;
int64_t count =
mongoc_collection_count_documents (coll,
tmp_bson ("{'finished': true}"),
NULL /* opts */,
NULL /* read_prefs */,
NULL /* reply */,
&error);
ASSERT_OR_PRINT (-1 != count, error);
return count == 1;
}

static void
test_bulk_reply_w0 (void)
Expand All @@ -4233,12 +4249,18 @@ test_bulk_reply_w0 (void)
mongoc_bulk_operation_update (
bulk, tmp_bson ("{}"), tmp_bson ("{'$set': {'x': 1}}"), false);
mongoc_bulk_operation_remove (bulk, tmp_bson ("{}"));
mongoc_bulk_operation_insert (bulk, tmp_bson ("{'finished': true}"));

ASSERT_OR_PRINT (mongoc_bulk_operation_execute (bulk, &reply, &error),
error);

ASSERT (bson_empty (&reply));

// Wait for the last insert to finish applying before proceeding to the next
// test. Otherwise, the commands may trigger failpoints of other tests (see
// CDRIVER-4539).
WAIT_UNTIL (test_bulk_reply_w0_finished (collection));

bson_destroy (&reply);
mongoc_bulk_operation_destroy (bulk);
bson_destroy (&opts);
Expand Down Expand Up @@ -4947,6 +4969,7 @@ test_bulk_write_multiple_errors (void *unused)

client = test_framework_new_default_client ();
BSON_ASSERT (client);
mongoc_client_set_appname (client, "test_bulk_write_multiple_errors");

collection = get_test_collection (client, "test_bulk_write_multiple_errors");
BSON_ASSERT (collection);
Expand All @@ -4955,15 +4978,13 @@ test_bulk_write_multiple_errors (void *unused)
// the first error.
bson_append_bool (&opts, "ordered", 7, false);
bulk = mongoc_collection_create_bulk_operation_with_opts (collection, &opts);
// Insert three documents. This is sent as one "insert" command to the
// server.
// configure fail point
// Use appName to isolate the failpoint to this test.
bool ret = mongoc_client_command_simple (
client,
"admin",
tmp_bson (
"{'configureFailPoint': 'failCommand', 'mode': {'times': 2}, "
"'data': {'failCommands': ['insert', 'delete'], 'errorCode': 8}}"),
tmp_bson ("{'configureFailPoint': 'failCommand', 'mode': {'times': 2}, "
"'data': {'failCommands': ['insert', 'delete'], 'errorCode': "
"8, 'appName': 'test_bulk_write_multiple_errors'}}"),
NULL,
NULL,
&error);
Expand Down Expand Up @@ -5307,5 +5328,7 @@ test_bulk_install (TestSuite *suite)
test_bulk_write_multiple_errors,
NULL,
NULL,
test_framework_skip_if_no_failpoint);
test_framework_skip_if_no_failpoint,
/* Require server 4.2 for failCommand appName */
test_framework_skip_if_max_wire_version_less_than_8);
}