Skip to content

Commit 885180b

Browse files
committed
CDRIVER-1023: Make sure we can read what we wrote
1 parent b57be13 commit 885180b

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

tests/test-bulk.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,12 @@ test_upsert_large ()
886886
bson_t *sel = tmp_bson ("{'_id': 1}");
887887
bson_t doc = BSON_INITIALIZER;
888888
bson_t child = BSON_INITIALIZER;
889+
bson_t query = BSON_INITIALIZER;
890+
const bson_t *retdoc;
889891
bson_error_t error;
890892
bson_t reply;
893+
mongoc_cursor_t *cursor;
894+
int ok = 0;
891895

892896
client = test_framework_client_new ();
893897
assert (client);
@@ -919,8 +923,28 @@ test_upsert_large ()
919923
check_n_modified (has_write_cmds, &reply, 0);
920924
ASSERT_COUNT (1, collection);
921925

926+
cursor = mongoc_collection_find (collection,
927+
MONGOC_QUERY_NONE,
928+
0,
929+
0,
930+
0,
931+
&query,
932+
NULL,
933+
NULL);
934+
while (mongoc_cursor_next (cursor, &retdoc)) {
935+
ok++;
936+
}
937+
ASSERT_CMPINT (ok, ==, 1);
938+
939+
if (mongoc_cursor_error (cursor, &error)) {
940+
fprintf (stderr, "ERROR: %s\n", error.message);
941+
ASSERT (false);
942+
}
943+
944+
bson_destroy (&query);
922945
bson_destroy (&reply);
923946
bson_destroy (&doc);
947+
mongoc_cursor_destroy (cursor);
924948
mongoc_bulk_operation_destroy (bulk);
925949
mongoc_collection_destroy (collection);
926950
mongoc_client_destroy (client);
@@ -1965,6 +1989,10 @@ test_large_inserts_ordered (void)
19651989
bson_t *big_doc;
19661990
bson_iter_t iter;
19671991
int i;
1992+
const bson_t *retdoc;
1993+
bson_t query = BSON_INITIALIZER;
1994+
mongoc_cursor_t *cursor;
1995+
int ok = 0;
19681996

19691997
client = test_framework_client_new ();
19701998
assert (client);
@@ -2008,6 +2036,26 @@ test_large_inserts_ordered (void)
20082036
check_n_modified (has_write_cmds, &reply, 0);
20092037
ASSERT_COUNT (1, collection);
20102038

2039+
cursor = mongoc_collection_find (collection,
2040+
MONGOC_QUERY_NONE,
2041+
0,
2042+
0,
2043+
0,
2044+
&query,
2045+
NULL,
2046+
NULL);
2047+
while (mongoc_cursor_next (cursor, &retdoc)) {
2048+
ok++;
2049+
}
2050+
2051+
ASSERT_CMPINT (ok, ==, 1);
2052+
2053+
if (mongoc_cursor_error (cursor, &error)) {
2054+
fprintf (stderr, "ERROR: %s\n", error.message);
2055+
ASSERT (false);
2056+
}
2057+
2058+
bson_destroy (&query);
20112059
mongoc_collection_remove (collection, MONGOC_REMOVE_NONE, tmp_bson ("{}"),
20122060
NULL, NULL);
20132061

@@ -2051,6 +2099,10 @@ test_large_inserts_unordered ()
20512099
bson_t *big_doc;
20522100
bson_iter_t iter;
20532101
int i;
2102+
const bson_t *retdoc;
2103+
bson_t query = BSON_INITIALIZER;
2104+
mongoc_cursor_t *cursor;
2105+
int ok = 0;
20542106

20552107
client = test_framework_client_new ();
20562108
assert (client);
@@ -2089,6 +2141,26 @@ test_large_inserts_unordered ()
20892141

20902142
ASSERT_COUNT (2, collection);
20912143

2144+
cursor = mongoc_collection_find (collection,
2145+
MONGOC_QUERY_NONE,
2146+
0,
2147+
0,
2148+
0,
2149+
&query,
2150+
NULL,
2151+
NULL);
2152+
while (mongoc_cursor_next (cursor, &retdoc)) {
2153+
ok++;
2154+
}
2155+
2156+
ASSERT_CMPINT (ok, ==, 2);
2157+
2158+
if (mongoc_cursor_error (cursor, &error)) {
2159+
fprintf (stderr, "ERROR: %s\n", error.message);
2160+
ASSERT (false);
2161+
}
2162+
2163+
bson_destroy (&query);
20922164
mongoc_collection_remove (collection, MONGOC_REMOVE_NONE, tmp_bson ("{}"),
20932165
NULL, NULL);
20942166

0 commit comments

Comments
 (0)