Skip to content

Commit 9657a3e

Browse files
committed
Update tests to account for retryable handshake network failures
1 parent dca28b0 commit 9657a3e

File tree

4 files changed

+60
-25
lines changed

4 files changed

+60
-25
lines changed

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@ test_mongoc_client_speculative_auth_failure (bool pooled)
480480
mongoc_collection_t *collection;
481481
mongoc_client_t *auth_client;
482482
mongoc_client_pool_t *pool;
483-
mongoc_uri_t *uri;
484483
mongoc_cursor_t *cursor;
485484
const bson_t *doc;
486485
bson_error_t error;
@@ -516,16 +515,21 @@ test_mongoc_client_speculative_auth_failure (bool pooled)
516515
uri_str_auth =
517516
test_framework_add_user_password (uri_str_no_auth, username, "testpass");
518517

519-
if (pooled) {
520-
uri = mongoc_uri_new (uri_str_auth);
521-
pool = test_framework_client_pool_new_from_uri (uri, NULL);
522-
mongoc_uri_destroy (uri);
518+
{
519+
mongoc_uri_t *const uri = mongoc_uri_new (uri_str_auth);
523520

524-
test_framework_set_pool_ssl_opts (pool);
525-
auth_client = mongoc_client_pool_pop (pool);
526-
} else {
527-
auth_client = test_framework_client_new (uri_str_auth, NULL);
528-
test_framework_set_ssl_opts (auth_client);
521+
ASSERT (
522+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false));
523+
524+
if (pooled) {
525+
pool = test_framework_client_pool_new_from_uri (uri, NULL);
526+
test_framework_set_pool_ssl_opts (pool);
527+
auth_client = mongoc_client_pool_pop (pool);
528+
} else {
529+
auth_client = test_framework_client_new_from_uri (uri, NULL);
530+
test_framework_set_ssl_opts (auth_client);
531+
}
532+
mongoc_uri_destroy (uri);
529533
}
530534

531535
collection = mongoc_client_get_collection (auth_client, "test", "test");
@@ -631,11 +635,22 @@ test_mongoc_client_authenticate_cached (bool pooled)
631635
int i = 0;
632636
uint32_t server_id;
633637

634-
if (pooled) {
635-
pool = test_framework_new_default_client_pool ();
636-
client = mongoc_client_pool_pop (pool);
637-
} else {
638-
client = test_framework_new_default_client ();
638+
{
639+
mongoc_uri_t *const uri = test_framework_get_uri ();
640+
641+
// Avoid retryable handshakes from interfering with screwed-up cache.
642+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
643+
644+
if (pooled) {
645+
pool = test_framework_client_pool_new_from_uri (uri, NULL);
646+
test_framework_set_pool_ssl_opts (pool);
647+
client = mongoc_client_pool_pop (pool);
648+
} else {
649+
client = test_framework_client_new_from_uri (uri, NULL);
650+
test_framework_set_ssl_opts (client);
651+
}
652+
653+
mongoc_uri_destroy (uri);
639654
}
640655

641656
collection = mongoc_client_get_collection (client, "test", "test");

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,9 @@ _test_cluster_hello_fails (bool hangup)
13721372
mock_server_run (mock_server);
13731373
uri = mongoc_uri_copy (mock_server_get_uri (mock_server));
13741374
/* increase heartbeatFrequencyMS to prevent background server selection. */
1375-
mongoc_uri_set_option_as_int32 (uri, "heartbeatFrequencyMS", 99999);
1375+
mongoc_uri_set_option_as_int32 (uri, MONGOC_URI_HEARTBEATFREQUENCYMS, 99999);
1376+
/* prevent retryable handshakes from interfering with mock server hangups */
1377+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
13761378
pool = test_framework_client_pool_new_from_uri (uri, NULL);
13771379
mongoc_client_pool_set_error_api (pool, 2);
13781380
mongoc_uri_destroy (uri);
@@ -1437,8 +1439,14 @@ test_cluster_command_error (void)
14371439

14381440
server = mock_server_with_auto_hello (WIRE_VERSION_MIN);
14391441
mock_server_run (server);
1440-
client =
1441-
test_framework_client_new_from_uri (mock_server_get_uri (server), NULL);
1442+
1443+
{
1444+
mongoc_uri_t *const uri = mongoc_uri_copy (mock_server_get_uri (server));
1445+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
1446+
client = test_framework_client_new_from_uri (uri, NULL);
1447+
mongoc_uri_destroy (uri);
1448+
}
1449+
14421450
future = future_client_command_simple (client,
14431451
"db",
14441452
tmp_bson ("{'ping': 1}"),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ test_pre_handshake_error_does_not_clear_pool (void)
564564
mock_server_run (server);
565565
uri = mongoc_uri_copy (mock_server_get_uri (server));
566566
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_LOADBALANCED, true);
567+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
567568
pool = mongoc_client_pool_new (uri);
568569
client_1 = mongoc_client_pool_pop (pool);
569570
client_2 = mongoc_client_pool_pop (pool);

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ static void
788788
test_cooldown_rs (void)
789789
{
790790
mock_server_t *servers[2]; /* two secondaries, no primary */
791-
char *uri_str;
792791
int i;
793792
mongoc_client_t *client;
794793
mongoc_read_prefs_t *primary_pref;
@@ -804,12 +803,25 @@ test_cooldown_rs (void)
804803
mock_server_run (servers[i]);
805804
}
806805

807-
uri_str = bson_strdup_printf ("mongodb://localhost:%hu/?replicaSet=rs"
808-
"&serverSelectionTimeoutMS=100"
809-
"&connectTimeoutMS=100",
810-
mock_server_get_port (servers[0]));
806+
{
807+
char *uri_str =
808+
bson_strdup_printf ("mongodb://localhost:%hu/?replicaSet=rs"
809+
"&serverSelectionTimeoutMS=100"
810+
"&connectTimeoutMS=100",
811+
mock_server_get_port (servers[0]));
812+
813+
mongoc_uri_t *const uri = mongoc_uri_new_with_error (uri_str, &error);
814+
ASSERT_OR_PRINT (uri, error);
815+
816+
// Prevent retryable handshakes from interfering with mock server hangups.
817+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
818+
819+
client = test_framework_client_new_from_uri (uri, NULL);
820+
821+
bson_free (uri_str);
822+
mongoc_uri_destroy (uri);
823+
}
811824

812-
client = test_framework_client_new (uri_str, NULL);
813825
primary_pref = mongoc_read_prefs_new (MONGOC_READ_PRIMARY);
814826

815827
secondary_response =
@@ -894,7 +906,6 @@ test_cooldown_rs (void)
894906
mongoc_client_destroy (client);
895907
bson_free (secondary_response);
896908
bson_free (primary_response);
897-
bson_free (uri_str);
898909
mock_server_destroy (servers[0]);
899910
mock_server_destroy (servers[1]);
900911
}

0 commit comments

Comments
 (0)