-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-4093 fix versioned API sample tests #848
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
Changes from all commits
555d218
f6eaebe
ebe34bd
33251f6
0ddb170
9c8a5d4
afa584b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
*/ | ||
|
||
/* clang-format off */ | ||
#include <assert.h> | ||
#include <mongoc/mongoc.h> | ||
#include <mongoc/mongoc-util-private.h> | ||
#include <mongoc/mongoc-database-private.h> | ||
|
@@ -3435,6 +3436,20 @@ get_client (void) | |
return test_framework_new_default_client (); | ||
} | ||
|
||
/* Returns a test client without version API options configured. */ | ||
static mongoc_client_t * | ||
get_client_for_version_api_example (void) { | ||
mongoc_client_t *client; | ||
mongoc_uri_t *uri; | ||
|
||
uri = test_framework_get_uri (); | ||
client = mongoc_client_new_from_uri (uri); | ||
ASSERT (client); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming that since this is test code that we expect to just terminate, there's no need to release the "client" resource? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Callers of |
||
test_framework_set_ssl_opts (client); | ||
mongoc_uri_destroy (uri); | ||
return client; | ||
} | ||
|
||
static bool | ||
callback (mongoc_client_session_t *session, | ||
void *ctx, | ||
|
@@ -3592,12 +3607,13 @@ _test_sample_versioned_api_example_1 (void) | |
* client = mongoc_client_new (uri_sharded); | ||
*/ | ||
|
||
client = get_client (); | ||
/* Create a mongoc_client_t without server API options configured. */ | ||
client = get_client_for_version_api_example (); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This test sets server API options on the client. To avoid setting duplicate options, the client should not be created with default server API options. For more background: the environment variable
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth adding a comment in the code about the API options note? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, I added a note to say that |
||
|
||
mongoc_server_api_version_from_string ("1", &server_api_version); | ||
server_api = mongoc_server_api_new (server_api_version); | ||
|
||
mongoc_client_set_server_api (client, server_api, &error); | ||
assert (mongoc_client_set_server_api (client, server_api, &error)); | ||
/* End Versioned API Example 1 */ | ||
|
||
mongoc_client_destroy (client); | ||
|
@@ -3624,13 +3640,14 @@ _test_sample_versioned_api_example_2 (void) | |
* client = mongoc_client_new (uri_sharded); | ||
*/ | ||
|
||
client = get_client (); | ||
/* Create a mongoc_client_t without server API options configured. */ | ||
client = get_client_for_version_api_example (); | ||
|
||
mongoc_server_api_version_from_string ("1", &server_api_version); | ||
server_api = mongoc_server_api_new (server_api_version); | ||
mongoc_server_api_strict (server_api, true); | ||
|
||
mongoc_client_set_server_api (client, server_api, &error); | ||
assert (mongoc_client_set_server_api (client, server_api, &error)); | ||
/* End Versioned API Example 2 */ | ||
|
||
mongoc_client_destroy (client); | ||
|
@@ -3657,13 +3674,14 @@ _test_sample_versioned_api_example_3 (void) | |
* client = mongoc_client_new (uri_sharded); | ||
*/ | ||
|
||
client = get_client (); | ||
/* Create a mongoc_client_t without server API options configured. */ | ||
client = get_client_for_version_api_example (); | ||
|
||
mongoc_server_api_version_from_string ("1", &server_api_version); | ||
server_api = mongoc_server_api_new (server_api_version); | ||
mongoc_server_api_strict (server_api, false); | ||
|
||
mongoc_client_set_server_api (client, server_api, &error); | ||
assert (mongoc_client_set_server_api (client, server_api, &error)); | ||
/* End Versioned API Example 3 */ | ||
|
||
mongoc_client_destroy (client); | ||
|
@@ -3690,13 +3708,14 @@ _test_sample_versioned_api_example_4 (void) | |
* client = mongoc_client_new (uri_sharded); | ||
*/ | ||
|
||
client = get_client (); | ||
/* Create a mongoc_client_t without server API options configured. */ | ||
client = get_client_for_version_api_example (); | ||
|
||
mongoc_server_api_version_from_string ("1", &server_api_version); | ||
server_api = mongoc_server_api_new (server_api_version); | ||
mongoc_server_api_deprecation_errors (server_api, true); | ||
|
||
mongoc_client_set_server_api (client, server_api, &error); | ||
assert (mongoc_client_set_server_api (client, server_api, &error)); | ||
/* End Versioned API Example 4 */ | ||
|
||
mongoc_client_destroy (client); | ||
|
@@ -3725,7 +3744,8 @@ static void _test_sample_versioned_api_example_5_6_7_8 (void) { | |
int64_t count; | ||
bson_t *filter; | ||
|
||
client = get_client (); | ||
/* Create a mongoc_client_t without server API options configured. */ | ||
client = get_client_for_version_api_example (); | ||
mongoc_client_set_error_api (client, MONGOC_ERROR_API_VERSION_2); | ||
mongoc_server_api_version_from_string ("1", &server_api_version); | ||
server_api = mongoc_server_api_new (server_api_version); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
download-mongodb.sh is copied from mongodb-labs/driver-evergreen-tools. This is required to get 5.0 server version with SERVER-58794 fixed.
On 5.0.0, the collection
create
command fails against sharded clusters when a versioned API is required. That was causing this test-asan-5.0-sharded-noauth-nosasl-nossl test failure.