Skip to content

Remove client arg from test helpers #1372

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 7 commits into from
Apr 7, 2025

Conversation

kevinAlbs
Copy link
Collaborator

Summary

Remove client arg from test helpers that cache results.

Verified with this patch build: https://spruce.mongodb.com/version/67ee96310b754c000700e66c

Motivation

When working on CXX-3209 I was surprised to discover calling test_util::get_max_wire_version on a differently versioned mongocryptd returned the same value as the running mongod:

// Check maxWireVersion of mongocryptd:
mongocxx::client mongocryptd_client(uri("mongodb://localhost:27020"));
auto mwv = test_util::get_max_wire_version(mongocryptd_client); // same as the running mongod?!

The cause appeared to be due to cached results in test helpers:

// These frequently used network calls are cached to avoid bottlenecks during tests.
document::value get_is_master(client const& client) {
    static auto reply = client["admin"].run_command(make_document(kvp("isMaster", 1)));
    return reply;
}

Later calls ignore the client argument. To avoid surprising readers, the client argument is removed from these calls. The calls always use a client constructed with the URI "mongodb://localhost:27017". Overloads accepting a client can be added later as needed.

The replies to `isMaster`, `serverStatus`, and `find` on `config.shards` are cached. The `client` argument is (surprisingly) ignored after the first call. Remove the argument to signal that the default client is used.
@kevinAlbs kevinAlbs requested review from a user and eramongodb April 3, 2025 18:22
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change!

@kevinAlbs kevinAlbs merged commit 50cda18 into mongodb:master Apr 7, 2025
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants