Skip to content

Commit b87d180

Browse files
authored
CDRIVER-4346 unskip /BulkOperation/split (#1438)
* unskip `/BulkOperation/split` * use session in test operations * apply read and write concern majority * skip test if no sessions support
1 parent 54aa89c commit b87d180

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

.evergreen/etc/skip-tests.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
/mongohouse/runCommand # CDRIVER-4333
2727

2828
/change_stream/live/track_resume_token # (CDRIVER-4344) Condition 'bson_compare (resume_token, &doc2_rt) == 0' failed
29-
/BulkOperation/split # (CDRIVER-4346) Assert Failure: count of split_1512376901_50824 is 97759, not 100010
3029
/ClientPool/pop_timeout # (CDRIVER-4348) precondition failed: duration_usec / 1000 >= 1990
3130
/Client/get_handshake_hello_response/pooled # (CDRIVER-4349) Assert Failure: "Unknown" != "PossiblePrimary"
3231

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

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3485,19 +3485,21 @@ test_numerous_unordered (void *ctx)
34853485

34863486

34873487
static void
3488-
test_bulk_split (void)
3488+
test_bulk_split (void *ctx)
34893489
{
3490+
BSON_UNUSED (ctx);
3491+
34903492
mongoc_client_t *client;
34913493
mongoc_collection_t *collection;
34923494
bson_t opts = BSON_INITIALIZER;
34933495
mongoc_bulk_operation_t *bulk_op;
3494-
mongoc_write_concern_t *wc = mongoc_write_concern_new ();
34953496
bson_iter_t iter, error_iter, indexnum;
34963497
bson_t doc, result;
34973498
bson_error_t error;
34983499
int n_docs;
34993500
int i;
35003501
uint32_t r;
3502+
mongoc_client_session_t *session;
35013503

35023504
/* ensure we need two batches */
35033505
n_docs = (int) test_framework_max_write_batch_size () + 10;
@@ -3508,10 +3510,35 @@ test_bulk_split (void)
35083510
collection = get_test_collection (client, "split");
35093511
BSON_ASSERT (collection);
35103512

3511-
mongoc_write_concern_set_w (wc, 1);
3513+
// Apply settings to guarantee "read-your-own-writes" semantics.
3514+
// Intended to address undercounts reading results reported in CDRIVER-4346.
3515+
{
3516+
// https://www.mongodb.com/docs/manual/core/read-isolation-consistency-recency/#client-sessions-and-causal-consistency-guarantees
3517+
// describes how to guarantee "read-your-own-writes".
3518+
3519+
// Start a causally consistent session.
3520+
mongoc_session_opt_t *sopts = mongoc_session_opts_new ();
3521+
mongoc_session_opts_set_causal_consistency (sopts, true);
3522+
session = mongoc_client_start_session (client, sopts, NULL);
3523+
mongoc_session_opts_destroy (sopts);
3524+
3525+
// Apply read concern majority.
3526+
mongoc_read_concern_t *rc = mongoc_read_concern_new ();
3527+
mongoc_read_concern_set_level (rc, MONGOC_READ_CONCERN_LEVEL_MAJORITY);
3528+
mongoc_collection_set_read_concern (collection, rc);
3529+
mongoc_read_concern_destroy (rc);
3530+
3531+
// Apply write concern majority.
3532+
mongoc_write_concern_t *wc = mongoc_write_concern_new ();
3533+
mongoc_write_concern_set_w (wc, MONGOC_WRITE_CONCERN_W_MAJORITY);
3534+
mongoc_collection_set_write_concern (collection, wc);
3535+
mongoc_write_concern_destroy (wc);
3536+
}
3537+
35123538

3513-
mongoc_write_concern_append (wc, &opts);
35143539
bson_append_bool (&opts, "ordered", 7, false);
3540+
ASSERT_OR_PRINT (mongoc_client_session_append (session, &opts, &error),
3541+
error);
35153542
bulk_op =
35163543
mongoc_collection_create_bulk_operation_with_opts (collection, &opts);
35173544

@@ -3548,7 +3575,20 @@ test_bulk_split (void)
35483575
BSON_ASSERT (!r);
35493576

35503577
/* all 100,010 docs were inserted, either by the first or second bulk op */
3551-
ASSERT_COUNT (n_docs, collection);
3578+
{
3579+
bson_t count_opts = BSON_INITIALIZER;
3580+
ASSERT_OR_PRINT (
3581+
mongoc_client_session_append (session, &count_opts, &error), error);
3582+
int64_t count = mongoc_collection_count_documents (collection,
3583+
tmp_bson ("{}"),
3584+
&count_opts,
3585+
NULL /* read_prefs */,
3586+
NULL /* reply */,
3587+
&error);
3588+
ASSERT_OR_PRINT (count != -1, error);
3589+
ASSERT_CMPINT64 (count, ==, 100010);
3590+
bson_destroy (&count_opts);
3591+
}
35523592

35533593
/* result like {writeErrors: [{index: i, code: n, errmsg: ''}, ... ]} */
35543594
bson_iter_init_find (&iter, &result, "writeErrors");
@@ -3574,9 +3614,8 @@ test_bulk_split (void)
35743614
bson_destroy (&opts);
35753615
bson_destroy (&result);
35763616

3577-
mongoc_write_concern_destroy (wc);
3578-
35793617
mongoc_collection_destroy (collection);
3618+
mongoc_client_session_destroy (session);
35803619
mongoc_client_destroy (client);
35813620
}
35823621

@@ -5293,7 +5332,12 @@ test_bulk_install (TestSuite *suite)
52935332
suite, "/BulkOperation/OP_MSG/max_batch_size", test_bulk_max_batch_size);
52945333
TestSuite_AddLive (
52955334
suite, "/BulkOperation/OP_MSG/max_msg_size", test_bulk_max_msg_size);
5296-
TestSuite_AddLive (suite, "/BulkOperation/split", test_bulk_split);
5335+
TestSuite_AddFull (suite,
5336+
"/BulkOperation/split",
5337+
test_bulk_split,
5338+
NULL /* dtor */,
5339+
NULL /* ctx */,
5340+
test_framework_skip_if_no_sessions);
52975341
TestSuite_AddFull (suite,
52985342
"/BulkOperation/write_concern/split",
52995343
test_bulk_write_concern_split,

0 commit comments

Comments
 (0)