Skip to content

Disable retryable handshakes by default for mock server tests #1214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/libmongoc/tests/mock_server/mock-rs.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ make_uri (mongoc_array_t *servers)

uri = mongoc_uri_new (uri_str->str);

// Many mock server tests do not expect retryable handshakes. Disable by
// default: tests that expect or require retryable handshakes must opt-in.
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, false);

bson_string_free (uri_str, true);

return uri;
Expand Down
5 changes: 5 additions & 0 deletions src/libmongoc/tests/mock_server/mock-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ mock_server_run (mock_server_t *server)
bound_port);
server->uri = mongoc_uri_new (server->uri_str);

// Many mock server tests do not expect retryable handshakes. Disable by
// default: tests that expect or require retryable handshakes must opt-in.
mongoc_uri_set_option_as_bool (server->uri, MONGOC_URI_RETRYREADS, false);
mongoc_uri_set_option_as_bool (server->uri, MONGOC_URI_RETRYWRITES, false);

r = mcommon_thread_create (
&server->main_thread, main_thread, (void *) server);
BSON_ASSERT (r == 0);
Expand Down
3 changes: 0 additions & 3 deletions src/libmongoc/tests/test-mongoc-bulk.c
Original file line number Diff line number Diff line change
Expand Up @@ -2918,9 +2918,6 @@ test_unordered_bulk_writes_with_error (void)
mock_server_get_host_and_port (server));

uri = mongoc_uri_copy (mock_server_get_uri (server));
/* disable retryable writes, so we move to the next operation on error */
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, false);

client = test_framework_client_new_from_uri (uri, NULL);

collection = mongoc_client_get_collection (client, "db", "test");
Expand Down
3 changes: 0 additions & 3 deletions src/libmongoc/tests/test-mongoc-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ _test_cluster_node_disconnect (bool pooled)
mock_server_run (server);

uri = mongoc_uri_copy (mock_server_get_uri (server));
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);

if (pooled) {
pool = test_framework_client_pool_new_from_uri (uri, NULL);
Expand Down Expand Up @@ -1368,8 +1367,6 @@ _test_cluster_hello_fails (bool hangup)
uri = mongoc_uri_copy (mock_server_get_uri (mock_server));
/* increase heartbeatFrequencyMS to prevent background server selection. */
mongoc_uri_set_option_as_int32 (uri, MONGOC_URI_HEARTBEATFREQUENCYMS, 99999);
/* prevent retryable handshakes from interfering with mock server hangups */
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
pool = test_framework_client_pool_new_from_uri (uri, NULL);
mongoc_client_pool_set_error_api (pool, 2);
mongoc_uri_destroy (uri);
Expand Down
1 change: 0 additions & 1 deletion src/libmongoc/tests/test-mongoc-database.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,6 @@ test_get_collection_names_error (void)
WIRE_VERSION_MAX);
mock_server_run (server);
uri = mongoc_uri_copy (mock_server_get_uri (server));
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
client = test_framework_client_new_from_uri (uri, NULL);

database = mongoc_client_get_database (client, "test");
Expand Down
1 change: 0 additions & 1 deletion src/libmongoc/tests/test-mongoc-loadbalanced.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ test_pre_handshake_error_does_not_clear_pool (void)
mock_server_run (server);
uri = mongoc_uri_copy (mock_server_get_uri (server));
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_LOADBALANCED, true);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, false);
pool = mongoc_client_pool_new (uri);
client_1 = mongoc_client_pool_pop (pool);
client_2 = mongoc_client_pool_pop (pool);
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc/tests/test-mongoc-retryable-reads.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ test_cmd_helpers (void *ctx)
BSON_UNUSED (ctx);

uri = test_framework_get_uri ();
mongoc_uri_set_option_as_bool (uri, "retryReads", true);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYREADS, true);

client = test_framework_client_new_from_uri (uri, NULL);
mongoc_client_set_error_api (client, MONGOC_ERROR_API_VERSION_2);
Expand Down
20 changes: 12 additions & 8 deletions src/libmongoc/tests/test-mongoc-retryable-writes.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test_rs_failover (void)

mock_rs_run (rs);
uri = mongoc_uri_copy (mock_rs_get_uri (rs));
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
client = test_framework_client_new_from_uri (uri, NULL);
collection = mongoc_client_get_collection (client, "db", "collection");
cs = mongoc_client_start_session (client, NULL, &error);
Expand Down Expand Up @@ -144,7 +144,7 @@ test_command_with_opts (void *ctx)
BSON_UNUSED (ctx);

uri = test_framework_get_uri ();
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);

client = test_framework_client_new_from_uri (uri, NULL);
test_framework_set_ssl_opts (client);
Expand Down Expand Up @@ -216,7 +216,7 @@ test_insert_one_unacknowledged (void)
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
mock_server_run (server);
uri = mongoc_uri_copy (mock_server_get_uri (server));
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
client = test_framework_client_new_from_uri (uri, NULL);
collection = mongoc_client_get_collection (client, "db", "collection");

Expand Down Expand Up @@ -264,7 +264,7 @@ test_update_one_unacknowledged (void)
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
mock_server_run (server);
uri = mongoc_uri_copy (mock_server_get_uri (server));
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
client = test_framework_client_new_from_uri (uri, NULL);
collection = mongoc_client_get_collection (client, "db", "collection");

Expand Down Expand Up @@ -315,7 +315,7 @@ test_delete_one_unacknowledged (void)
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
mock_server_run (server);
uri = mongoc_uri_copy (mock_server_get_uri (server));
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
client = test_framework_client_new_from_uri (uri, NULL);
collection = mongoc_client_get_collection (client, "db", "collection");

Expand Down Expand Up @@ -363,7 +363,7 @@ test_bulk_operation_execute_unacknowledged (void)
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
mock_server_run (server);
uri = mongoc_uri_copy (mock_server_get_uri (server));
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
client = test_framework_client_new_from_uri (uri, NULL);
collection = mongoc_client_get_collection (client, "db", "collection");

Expand Down Expand Up @@ -412,7 +412,7 @@ test_remove_unacknowledged (void)
server = mock_mongos_new (WIRE_VERSION_RETRY_WRITES);
mock_server_run (server);
uri = mongoc_uri_copy (mock_server_get_uri (server));
mongoc_uri_set_option_as_bool (uri, "retryWrites", true);
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
client = test_framework_client_new_from_uri (uri, NULL);
collection = mongoc_client_get_collection (client, "db", "collection");

Expand Down Expand Up @@ -519,6 +519,7 @@ static void
test_unsupported_storage_engine_error (void)
{
mock_rs_t *rs;
mongoc_uri_t *uri;
mongoc_client_t *client;
mongoc_collection_t *coll;
bson_t reply;
Expand All @@ -533,7 +534,9 @@ test_unsupported_storage_engine_error (void)

rs = mock_rs_with_auto_hello (WIRE_VERSION_RETRY_WRITES, true, 0, 0);
mock_rs_run (rs);
client = test_framework_client_new_from_uri (mock_rs_get_uri (rs), NULL);
uri = mongoc_uri_copy (mock_rs_get_uri (rs));
mongoc_uri_set_option_as_bool (uri, MONGOC_URI_RETRYWRITES, true);
client = test_framework_client_new_from_uri (uri, NULL);
session = mongoc_client_start_session (client, NULL, &error);
ASSERT_OR_PRINT (session, error);
mongoc_client_set_error_api (client, MONGOC_ERROR_API_VERSION_2);
Expand Down Expand Up @@ -566,6 +569,7 @@ test_unsupported_storage_engine_error (void)
future_destroy (future);
mongoc_collection_destroy (coll);
mongoc_client_destroy (client);
mongoc_uri_destroy (uri);
mock_rs_destroy (rs);
}

Expand Down