Skip to content

Commit 792115a

Browse files
committed
CDRIVER-523 improve bulk tests
1 parent 14c31d4 commit 792115a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

tests/test-bulk.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,19 +1498,17 @@ test_multiple_error_ordered_bulk ()
14981498

14991499
mongoc_bulk_operation_insert (bulk,
15001500
tmp_bson ("{'b': 1, 'a': 1}"));
1501-
mongoc_bulk_operation_update (bulk,
1502-
tmp_bson ("{'b': 2}"),
1503-
tmp_bson ("{'$set': {'a': 1}}"), true);
1501+
/* succeeds */
15041502
mongoc_bulk_operation_update (bulk,
15051503
tmp_bson ("{'b': 3}"),
15061504
tmp_bson ("{'$set': {'a': 2}}"), true);
1505+
/* fails, duplicate value for 'a' */
15071506
mongoc_bulk_operation_update (bulk,
15081507
tmp_bson ("{'b': 2}"),
15091508
tmp_bson ("{'$set': {'a': 1}}"), true);
1509+
/* not attempted, bulk is already aborted */
15101510
mongoc_bulk_operation_insert (bulk,
15111511
tmp_bson ("{'b': 4, 'a': 3}"));
1512-
mongoc_bulk_operation_insert (bulk,
1513-
tmp_bson ("{'b': 5, 'a': 1}"));
15141512

15151513
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
15161514
assert (!r);
@@ -1520,7 +1518,7 @@ test_multiple_error_ordered_bulk ()
15201518
/* TODO: CDRIVER-651, assert contents of the 'op' field */
15211519
/* TODO: CDRIVER-656, assert writeErrors index is 1 */
15221520
ASSERT_MATCH (&reply, "{'nMatched': 0,"
1523-
" 'nUpserted': 0,"
1521+
" 'nUpserted': 1,"
15241522
" 'nInserted': 1,"
15251523
" 'nRemoved': 0,"
15261524
/*
@@ -1533,7 +1531,7 @@ test_multiple_error_ordered_bulk ()
15331531
"}");
15341532
check_n_modified (has_write_cmds, &reply, 0);
15351533
assert_error_count (1, &reply);
1536-
assert_count (1, collection);
1534+
assert_count (2, collection);
15371535

15381536
bson_destroy (&reply);
15391537
mongoc_bulk_operation_destroy (bulk);
@@ -1751,8 +1749,8 @@ test_large_inserts_ordered ()
17511749
client = test_framework_client_new (NULL);
17521750
assert (client);
17531751

1754-
huge_doc = BCON_NEW ('a', BCON_INT32 (1));
1755-
bson_append_utf8 (huge_doc, "huge", -1,
1752+
huge_doc = BCON_NEW ("a", BCON_INT32 (1));
1753+
bson_append_utf8 (huge_doc, "long-key-to-make-this-fail", -1,
17561754
huge_string (client), huge_string_length (client));
17571755

17581756
collection = get_test_collection (client, "test_large_inserts_ordered");
@@ -1766,7 +1764,7 @@ test_large_inserts_ordered ()
17661764

17671765
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
17681766
assert (!r);
1769-
ASSERT_CMPINT (error.domain, ==, MONGOC_ERROR_COMMAND);
1767+
ASSERT_CMPINT (error.domain, ==, MONGOC_ERROR_QUERY);
17701768
assert (error.code);
17711769

17721770
/* TODO: CDRIVER-654, assert nInserted == 1 */
@@ -1822,8 +1820,8 @@ test_large_inserts_unordered ()
18221820
client = test_framework_client_new (NULL);
18231821
assert (client);
18241822

1825-
huge_doc = tmp_bson ("{'a': 1}");
1826-
bson_append_utf8 (huge_doc, "huge", -1,
1823+
huge_doc = BCON_NEW ("a", BCON_INT32 (1));
1824+
bson_append_utf8 (huge_doc, "long-key-to-make-this-fail", -1,
18271825
huge_string (client), huge_string_length (client));
18281826

18291827
collection = get_test_collection (client, "test_large_inserts_unordered");
@@ -1837,7 +1835,7 @@ test_large_inserts_unordered ()
18371835

18381836
r = (bool)mongoc_bulk_operation_execute (bulk, &reply, &error);
18391837
assert (!r);
1840-
ASSERT_CMPINT (error.domain, ==, MONGOC_ERROR_COMMAND);
1838+
ASSERT_CMPINT (error.domain, ==, MONGOC_ERROR_QUERY);
18411839
assert (error.code);
18421840

18431841
/* TODO: CDRIVER-654, assert nInserted == 2 */
@@ -1868,6 +1866,7 @@ test_large_inserts_unordered ()
18681866
assert_count (6, collection);
18691867
*/
18701868

1869+
bson_destroy (huge_doc);
18711870
bson_destroy (&reply);
18721871
mongoc_bulk_operation_destroy (bulk);
18731872
mongoc_collection_destroy (collection);
@@ -2177,6 +2176,10 @@ test_bulk_install (TestSuite *suite)
21772176
test_upsert_unordered);
21782177
TestSuite_Add (suite, "/BulkOperation/upsert_large",
21792178
test_upsert_large);
2179+
TestSuite_Add (suite, "/BulkOperation/upserted_index_ordered",
2180+
test_upserted_index_ordered);
2181+
TestSuite_Add (suite, "/BulkOperation/upserted_index_unordered",
2182+
test_upserted_index_unordered);
21802183
TestSuite_Add (suite, "/BulkOperation/update_one_ordered",
21812184
test_update_one_ordered);
21822185
TestSuite_Add (suite, "/BulkOperation/update_one_unordered",

0 commit comments

Comments
 (0)