Skip to content

CDRIVER-4593: Handle double type connectionId #1222

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 5 commits into from
Mar 27, 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
2 changes: 1 addition & 1 deletion src/libmongoc/src/mongoc/mongoc-server-description.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
GOTO (typefailure);
bson_oid_copy_unsafe (bson_iter_oid (&iter), &sd->service_id);
} else if (strcmp ("connectionId", bson_iter_key (&iter)) == 0) {
if (!BSON_ITER_HOLDS_INT (&iter))
if (!BSON_ITER_HOLDS_NUMBER (&iter))
GOTO (typefailure);
sd->server_connection_id = bson_iter_as_int64 (&iter);
}
Expand Down
75 changes: 48 additions & 27 deletions src/libmongoc/tests/test-mongoc-server-description.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,33 +388,54 @@ test_server_description_connection_id (void)
bson_t *hello;
bson_error_t error;

mongoc_server_description_init (&sd, "host:1234", 1);
hello = BCON_NEW ("minWireVersion",
BCON_INT32 (WIRE_VERSION_MIN),
"maxWireVersion",
BCON_INT32 (WIRE_VERSION_MAX),
"connectionId",
BCON_INT32 (1));
memset (&error, 0, sizeof (bson_error_t));
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
BSON_ASSERT (sd.server_connection_id == 1);

mongoc_server_description_reset (&sd);
bson_destroy (hello);
hello = BCON_NEW ("minWireVersion",
BCON_INT32 (WIRE_VERSION_MIN),
"maxWireVersion",
BCON_INT32 (WIRE_VERSION_MAX),
"connectionId",
BCON_INT64 (1));
memset (&error, 0, sizeof (bson_error_t));
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
BSON_ASSERT (sd.server_connection_id == 1);

bson_destroy (hello);
mongoc_server_description_cleanup (&sd);
// Test an int32.
{
mongoc_server_description_init (&sd, "host:1234", 1);
hello = BCON_NEW ("minWireVersion",
BCON_INT32 (WIRE_VERSION_MIN),
"maxWireVersion",
BCON_INT32 (WIRE_VERSION_MAX),
"connectionId",
BCON_INT32 (1));
memset (&error, 0, sizeof (bson_error_t));
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
ASSERT_CMPINT64 (sd.server_connection_id, ==, 1);
mongoc_server_description_cleanup (&sd);
bson_destroy (hello);
}
// Test an int64.
{
mongoc_server_description_init (&sd, "host:1234", 1);
hello = BCON_NEW ("minWireVersion",
BCON_INT32 (WIRE_VERSION_MIN),
"maxWireVersion",
BCON_INT32 (WIRE_VERSION_MAX),
"connectionId",
BCON_INT64 (1));
memset (&error, 0, sizeof (bson_error_t));
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
ASSERT_CMPINT64 (sd.server_connection_id, ==, 1);
bson_destroy (hello);
mongoc_server_description_cleanup (&sd);
}
// Test a double.
{
mongoc_server_description_init (&sd, "host:1234", 1);
hello = BCON_NEW ("minWireVersion",
BCON_INT32 (WIRE_VERSION_MIN),
"maxWireVersion",
BCON_INT32 (WIRE_VERSION_MAX),
"connectionId",
BCON_DOUBLE (1));
memset (&error, 0, sizeof (bson_error_t));
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
BSON_ASSERT (sd.server_connection_id == 1);
Copy link
Member

Choose a reason for hiding this comment

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

I think this should have used ASSERT_CMPINT64 since libmongoc still stores the value as an int64_t; however, it probably makes little difference in practice.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed. PR posted: #1223

bson_destroy (hello);
mongoc_server_description_cleanup (&sd);
}
}

static void
Expand Down