Skip to content

Commit 3d5f0eb

Browse files
committed
CDRIVER-497 fix test failures with mongos
1 parent ed77cb8 commit 3d5f0eb

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

tests/TestSuite.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ TestSuite_PrintJsonHeader (TestSuite *suite, /* IN */
524524
fprintf (stream,
525525
"{\n"
526526
" \"uri\": \"%s\",\n"
527+
" \"is_mongos\": \"%s\",\n"
527528
" \"host\": {\n"
528529
" \"sysname\": \"Windows\",\n"
529530
" \"release\": \"%ld.%ld (%ld)\",\n"
@@ -539,6 +540,7 @@ TestSuite_PrintJsonHeader (TestSuite *suite, /* IN */
539540
" },\n"
540541
" \"tests\": [\n",
541542
test_framework_get_uri_str (),
543+
test_framework_is_mongos () ? "true" : "false",
542544
major_version, minor_version, build,
543545
si.dwProcessorType,
544546
si.dwPageSize,
@@ -566,6 +568,7 @@ TestSuite_PrintJsonHeader (TestSuite *suite, /* IN */
566568
fprintf (stream,
567569
"{\n"
568570
" \"uri\": \"%s\",\n"
571+
" \"is_mongos\": \"%s\",\n"
569572
" \"host\": {\n"
570573
" \"sysname\": \"%s\",\n"
571574
" \"release\": \"%s\",\n"
@@ -581,6 +584,7 @@ TestSuite_PrintJsonHeader (TestSuite *suite, /* IN */
581584
" },\n"
582585
" \"tests\": [\n",
583586
test_framework_get_uri_str (),
587+
test_framework_is_mongos () ? "true" : "false",
584588
u.sysname,
585589
u.release,
586590
u.machine,

tests/test-libmongoc.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,25 @@ test_framework_global_ssl_opts_cleanup (void)
849849
}
850850
#endif
851851

852+
853+
bool
854+
test_framework_is_mongos (void)
855+
{
856+
bson_t reply;
857+
bson_iter_t iter;
858+
bool is_mongos;
859+
860+
call_ismaster (&reply);
861+
862+
is_mongos = (bson_iter_init_find (&iter, &reply, "msg")
863+
&& BSON_ITER_HOLDS_UTF8 (&iter)
864+
&& !strcasecmp (bson_iter_utf8 (&iter, NULL), "isdbgrid"));
865+
866+
bson_destroy (&reply);
867+
868+
return is_mongos;
869+
}
870+
852871
int
853872
main (int argc,
854873
char *argv[])

tests/test-libmongoc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ char *test_framework_get_uri_str (void);
3535
mongoc_uri_t *test_framework_get_uri (void);
3636
mongoc_client_t *test_framework_client_new (void);
3737
mongoc_client_pool_t *test_framework_client_pool_new (void);
38+
bool test_framework_is_mongos (void);
3839
#endif

tests/test-mongoc-client.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ int should_run_auth_tests (void)
155155
}
156156

157157

158+
int skip_if_mongos (void)
159+
{
160+
return test_framework_is_mongos () ? 0 : 1;
161+
}
162+
163+
158164
static void
159165
test_mongoc_client_authenticate_failure (void *context)
160166
{
@@ -652,7 +658,7 @@ test_recovering (void)
652658

653659

654660
static void
655-
test_exhaust_cursor (void)
661+
test_exhaust_cursor (void *context)
656662
{
657663
mongoc_stream_t *stream;
658664
mongoc_write_concern_t *wr;
@@ -955,7 +961,7 @@ test_client_install (TestSuite *suite)
955961
TestSuite_Add (suite, "/Client/mongos_seeds_reconnect", test_mongos_seeds_reconnect);
956962
TestSuite_Add (suite, "/Client/recovering", test_recovering);
957963
#endif
958-
TestSuite_Add (suite, "/Client/exhaust_cursor", test_exhaust_cursor);
964+
TestSuite_AddFull (suite, "/Client/exhaust_cursor", test_exhaust_cursor, NULL, NULL, skip_if_mongos);
959965
TestSuite_Add (suite, "/Client/server_status", test_server_status);
960966
TestSuite_Add (suite, "/Client/database_names", test_get_database_names);
961967

tests/test-mongoc-collection.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,6 @@ test_validate (void)
13381338
r = mongoc_collection_validate (collection, &opts, &reply, &error);
13391339
assert (r);
13401340

1341-
assert (bson_iter_init_find (&iter, &reply, "ns"));
13421341
assert (bson_iter_init_find (&iter, &reply, "valid"));
13431342

13441343
bson_destroy (&reply);

0 commit comments

Comments
 (0)