Skip to content

Commit 2b370c8

Browse files
kvalagondakevinAlbs
andcommitted
CDRIVER-4593: Handle double type connectionId (#1222)
* CDRIVER-4593: Handle double type connectionId * use scopes in test_server_description_connection_id * use cleanup instead of reset * use ASSERT_CMPINT64 * add test for double --------- Co-authored-by: Kevin Albertson <[email protected]>
1 parent bb9526c commit 2b370c8

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

src/libmongoc/src/mongoc/mongoc-server-description.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
740740
GOTO (typefailure);
741741
bson_oid_copy_unsafe (bson_iter_oid (&iter), &sd->service_id);
742742
} else if (strcmp ("connectionId", bson_iter_key (&iter)) == 0) {
743-
if (!BSON_ITER_HOLDS_INT (&iter))
743+
if (!BSON_ITER_HOLDS_NUMBER (&iter))
744744
GOTO (typefailure);
745745
sd->server_connection_id = bson_iter_as_int64 (&iter);
746746
}

src/libmongoc/tests/test-mongoc-server-description.c

+48-27
Original file line numberDiff line numberDiff line change
@@ -388,33 +388,54 @@ test_server_description_connection_id (void)
388388
bson_t *hello;
389389
bson_error_t error;
390390

391-
mongoc_server_description_init (&sd, "host:1234", 1);
392-
hello = BCON_NEW ("minWireVersion",
393-
BCON_INT32 (WIRE_VERSION_MIN),
394-
"maxWireVersion",
395-
BCON_INT32 (WIRE_VERSION_MAX),
396-
"connectionId",
397-
BCON_INT32 (1));
398-
memset (&error, 0, sizeof (bson_error_t));
399-
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
400-
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
401-
BSON_ASSERT (sd.server_connection_id == 1);
402-
403-
mongoc_server_description_reset (&sd);
404-
bson_destroy (hello);
405-
hello = BCON_NEW ("minWireVersion",
406-
BCON_INT32 (WIRE_VERSION_MIN),
407-
"maxWireVersion",
408-
BCON_INT32 (WIRE_VERSION_MAX),
409-
"connectionId",
410-
BCON_INT64 (1));
411-
memset (&error, 0, sizeof (bson_error_t));
412-
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
413-
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
414-
BSON_ASSERT (sd.server_connection_id == 1);
415-
416-
bson_destroy (hello);
417-
mongoc_server_description_cleanup (&sd);
391+
// Test an int32.
392+
{
393+
mongoc_server_description_init (&sd, "host:1234", 1);
394+
hello = BCON_NEW ("minWireVersion",
395+
BCON_INT32 (WIRE_VERSION_MIN),
396+
"maxWireVersion",
397+
BCON_INT32 (WIRE_VERSION_MAX),
398+
"connectionId",
399+
BCON_INT32 (1));
400+
memset (&error, 0, sizeof (bson_error_t));
401+
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
402+
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
403+
ASSERT_CMPINT64 (sd.server_connection_id, ==, 1);
404+
mongoc_server_description_cleanup (&sd);
405+
bson_destroy (hello);
406+
}
407+
// Test an int64.
408+
{
409+
mongoc_server_description_init (&sd, "host:1234", 1);
410+
hello = BCON_NEW ("minWireVersion",
411+
BCON_INT32 (WIRE_VERSION_MIN),
412+
"maxWireVersion",
413+
BCON_INT32 (WIRE_VERSION_MAX),
414+
"connectionId",
415+
BCON_INT64 (1));
416+
memset (&error, 0, sizeof (bson_error_t));
417+
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
418+
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
419+
ASSERT_CMPINT64 (sd.server_connection_id, ==, 1);
420+
bson_destroy (hello);
421+
mongoc_server_description_cleanup (&sd);
422+
}
423+
// Test a double.
424+
{
425+
mongoc_server_description_init (&sd, "host:1234", 1);
426+
hello = BCON_NEW ("minWireVersion",
427+
BCON_INT32 (WIRE_VERSION_MIN),
428+
"maxWireVersion",
429+
BCON_INT32 (WIRE_VERSION_MAX),
430+
"connectionId",
431+
BCON_DOUBLE (1));
432+
memset (&error, 0, sizeof (bson_error_t));
433+
mongoc_server_description_handle_hello (&sd, hello, 0 /* rtt */, &error);
434+
BSON_ASSERT (sd.type == MONGOC_SERVER_STANDALONE);
435+
BSON_ASSERT (sd.server_connection_id == 1);
436+
bson_destroy (hello);
437+
mongoc_server_description_cleanup (&sd);
438+
}
418439
}
419440

420441
static void

0 commit comments

Comments
 (0)