Skip to content

Commit d44babf

Browse files
authored
Disable retryable handshakes by default for mock server tests (#1214)
1 parent 1c2da95 commit d44babf

File tree

8 files changed

+23
-17
lines changed

8 files changed

+23
-17
lines changed

src/libmongoc/tests/mock_server/mock-rs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ make_uri (mongoc_array_t *servers)
103103

104104
uri = mongoc_uri_new (uri_str->str);
105105

106+
// Many mock server tests do not expect retryable handshakes. Disable by
107+
// default: tests that expect or require retryable handshakes must opt-in.
108+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
109+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, false);
110+
106111
bson_string_free (uri_str, true);
107112

108113
return uri;

src/libmongoc/tests/mock_server/mock-server.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@ mock_server_run (mock_server_t *server)
391391
bound_port);
392392
server->uri = mongoc_uri_new (server->uri_str);
393393

394+
// Many mock server tests do not expect retryable handshakes. Disable by
395+
// default: tests that expect or require retryable handshakes must opt-in.
396+
mongoc_uri_set_option_as_bool (server->uri, MONGOC_URI_RETRYREADS, false);
397+
mongoc_uri_set_option_as_bool (server->uri, MONGOC_URI_RETRYWRITES, false);
398+
394399
r = mcommon_thread_create (
395400
&server->main_thread, main_thread, (void *) server);
396401
BSON_ASSERT (r == 0);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,9 +2918,6 @@ test_unordered_bulk_writes_with_error (void)
29182918
mock_server_get_host_and_port (server));
29192919

29202920
uri = mongoc_uri_copy (mock_server_get_uri (server));
2921-
/* disable retryable writes, so we move to the next operation on error */
2922-
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, false);
2923-
29242921
client = test_framework_client_new_from_uri (uri, NULL);
29252922

29262923
collection = mongoc_client_get_collection (client, "db", "test");

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ _test_cluster_node_disconnect (bool pooled)
174174
mock_server_run (server);
175175

176176
uri = mongoc_uri_copy (mock_server_get_uri (server));
177-
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
178177

179178
if (pooled) {
180179
pool = test_framework_client_pool_new_from_uri (uri, NULL);
@@ -1368,8 +1367,6 @@ _test_cluster_hello_fails (bool hangup)
13681367
uri = mongoc_uri_copy (mock_server_get_uri (mock_server));
13691368
/* increase heartbeatFrequencyMS to prevent background server selection. */
13701369
mongoc_uri_set_option_as_int32 (uri, MONGOC_URI_HEARTBEATFREQUENCYMS, 99999);
1371-
/* prevent retryable handshakes from interfering with mock server hangups */
1372-
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
13731370
pool = test_framework_client_pool_new_from_uri (uri, NULL);
13741371
mongoc_client_pool_set_error_api (pool, 2);
13751372
mongoc_uri_destroy (uri);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,6 @@ test_get_collection_names_error (void)
10891089
WIRE_VERSION_MAX);
10901090
mock_server_run (server);
10911091
uri = mongoc_uri_copy (mock_server_get_uri (server));
1092-
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
10931092
client = test_framework_client_new_from_uri (uri, NULL);
10941093

10951094
database = mongoc_client_get_database (client, "test");

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,6 @@ 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);
568567
pool = mongoc_client_pool_new (uri);
569568
client_1 = mongoc_client_pool_pop (pool);
570569
client_2 = mongoc_client_pool_pop (pool);

src/libmongoc/tests/test-mongoc-retryable-reads.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ test_cmd_helpers (void *ctx)
9393
BSON_UNUSED (ctx);
9494

9595
uri = test_framework_get_uri ();
96-
mongoc_uri_set_option_as_bool (uri, "retryReads", true);
96+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, true);
9797

9898
client = test_framework_client_new_from_uri (uri, NULL);
9999
mongoc_client_set_error_api (client, MONGOC_ERROR_API_VERSION_2);

src/libmongoc/tests/test-mongoc-retryable-writes.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ test_rs_failover (void)
8080

8181
mock_rs_run (rs);
8282
uri = mongoc_uri_copy (mock_rs_get_uri (rs));
83-
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
83+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
8484
client = test_framework_client_new_from_uri (uri, NULL);
8585
collection = mongoc_client_get_collection (client, "db", "collection");
8686
cs = mongoc_client_start_session (client, NULL, &error);
@@ -144,7 +144,7 @@ test_command_with_opts (void *ctx)
144144
BSON_UNUSED (ctx);
145145

146146
uri = test_framework_get_uri ();
147-
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
147+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
148148

149149
client = test_framework_client_new_from_uri (uri, NULL);
150150
test_framework_set_ssl_opts (client);
@@ -216,7 +216,7 @@ test_insert_one_unacknowledged (void)
216216
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
217217
mock_server_run (server);
218218
uri = mongoc_uri_copy (mock_server_get_uri (server));
219-
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
219+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
220220
client = test_framework_client_new_from_uri (uri, NULL);
221221
collection = mongoc_client_get_collection (client, "db", "collection");
222222

@@ -264,7 +264,7 @@ test_update_one_unacknowledged (void)
264264
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
265265
mock_server_run (server);
266266
uri = mongoc_uri_copy (mock_server_get_uri (server));
267-
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
267+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
268268
client = test_framework_client_new_from_uri (uri, NULL);
269269
collection = mongoc_client_get_collection (client, "db", "collection");
270270

@@ -315,7 +315,7 @@ test_delete_one_unacknowledged (void)
315315
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
316316
mock_server_run (server);
317317
uri = mongoc_uri_copy (mock_server_get_uri (server));
318-
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
318+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
319319
client = test_framework_client_new_from_uri (uri, NULL);
320320
collection = mongoc_client_get_collection (client, "db", "collection");
321321

@@ -363,7 +363,7 @@ test_bulk_operation_execute_unacknowledged (void)
363363
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
364364
mock_server_run (server);
365365
uri = mongoc_uri_copy (mock_server_get_uri (server));
366-
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
366+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
367367
client = test_framework_client_new_from_uri (uri, NULL);
368368
collection = mongoc_client_get_collection (client, "db", "collection");
369369

@@ -412,7 +412,7 @@ test_remove_unacknowledged (void)
412412
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
413413
mock_server_run (server);
414414
uri = mongoc_uri_copy (mock_server_get_uri (server));
415-
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
415+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
416416
client = test_framework_client_new_from_uri (uri, NULL);
417417
collection = mongoc_client_get_collection (client, "db", "collection");
418418

@@ -519,6 +519,7 @@ static void
519519
test_unsupported_storage_engine_error (void)
520520
{
521521
mock_rs_t *rs;
522+
mongoc_uri_t *uri;
522523
mongoc_client_t *client;
523524
mongoc_collection_t *coll;
524525
bson_t reply;
@@ -533,7 +534,9 @@ test_unsupported_storage_engine_error (void)
533534

534535
rs = mock_rs_with_auto_hello (WIRE_VERSION_RETRY_WRITES, true, 0, 0);
535536
mock_rs_run (rs);
536-
client = test_framework_client_new_from_uri (mock_rs_get_uri (rs), NULL);
537+
uri = mongoc_uri_copy (mock_rs_get_uri (rs));
538+
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
539+
client = test_framework_client_new_from_uri (uri, NULL);
537540
session = mongoc_client_start_session (client, NULL, &error);
538541
ASSERT_OR_PRINT (session, error);
539542
mongoc_client_set_error_api (client, MONGOC_ERROR_API_VERSION_2);
@@ -566,6 +569,7 @@ test_unsupported_storage_engine_error (void)
566569
future_destroy (future);
567570
mongoc_collection_destroy (coll);
568571
mongoc_client_destroy (client);
572+
mongoc_uri_destroy (uri);
569573
mock_rs_destroy (rs);
570574
}
571575

0 commit comments

Comments
 (0)