Skip to content

Commit d223333

Browse files
committed
Drop test collection with writeConcern=majority (#1235)
* improve assertion * drop collection with writeConcern majority in `test_count_read_concern_live`
1 parent dc6f98d commit d223333

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,14 +2243,31 @@ test_count_read_concern_live (void *unused)
22432243
collection = mongoc_client_get_collection (client, "test", "test");
22442244
ASSERT (collection);
22452245

2246-
/* don't care if ns not found. */
2247-
(void) mongoc_collection_drop (collection, &error);
2246+
// Drop collection.
2247+
// Use writeConcern=majority so later readConcern=majority observes dropped
2248+
// collection.
2249+
{
2250+
mongoc_write_concern_t *wc = mongoc_write_concern_new ();
2251+
mongoc_write_concern_set_w (wc, MONGOC_WRITE_CONCERN_W_MAJORITY);
2252+
bson_t drop_opts = BSON_INITIALIZER;
2253+
mongoc_write_concern_append (wc, &drop_opts);
2254+
if (!mongoc_collection_drop_with_opts (collection, &drop_opts, &error)) {
2255+
// Ignore an "ns not found" error.
2256+
if (NULL == strstr (error.message, "ns not found")) {
2257+
ASSERT_OR_PRINT (false, error);
2258+
}
2259+
}
2260+
2261+
bson_destroy (&drop_opts);
2262+
mongoc_write_concern_destroy (wc);
2263+
}
22482264

22492265
bson_init (&b);
22502266
count = mongoc_collection_count (
22512267
collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error);
22522268
bson_destroy (&b);
2253-
ASSERT_OR_PRINT (count == 0, error);
2269+
ASSERT_OR_PRINT (count != -1, error);
2270+
ASSERT_CMPINT64 (count, ==, 0);
22542271

22552272
/* Setting readConcern to NULL should not send readConcern */
22562273
rc = mongoc_read_concern_new ();
@@ -2261,7 +2278,8 @@ test_count_read_concern_live (void *unused)
22612278
count = mongoc_collection_count (
22622279
collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error);
22632280
bson_destroy (&b);
2264-
ASSERT_OR_PRINT (count == 0, error);
2281+
ASSERT_OR_PRINT (count != -1, error);
2282+
ASSERT_CMPINT64 (count, ==, 0);
22652283
mongoc_read_concern_destroy (rc);
22662284

22672285
/* readConcern: { level: local } should raise error pre 3.2 */
@@ -2273,7 +2291,8 @@ test_count_read_concern_live (void *unused)
22732291
count = mongoc_collection_count (
22742292
collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error);
22752293
bson_destroy (&b);
2276-
ASSERT_OR_PRINT (count == 0, error);
2294+
ASSERT_OR_PRINT (count != -1, error);
2295+
ASSERT_CMPINT64 (count, ==, 0);
22772296
mongoc_read_concern_destroy (rc);
22782297

22792298
/* readConcern: { level: majority } should raise error pre 3.2 */
@@ -2285,7 +2304,8 @@ test_count_read_concern_live (void *unused)
22852304
count = mongoc_collection_count (
22862305
collection, MONGOC_QUERY_NONE, &b, 0, 0, NULL, &error);
22872306
bson_destroy (&b);
2288-
ASSERT_OR_PRINT (count == 0, error);
2307+
ASSERT_OR_PRINT (count != -1, error);
2308+
ASSERT_CMPINT64 (count, ==, 0);
22892309
mongoc_read_concern_destroy (rc);
22902310

22912311
mongoc_collection_destroy (collection);

0 commit comments

Comments
 (0)