@@ -2313,6 +2313,7 @@ _test_hello_ok (bool pooled)
2313
2313
mongoc_client_pool_t * pool ;
2314
2314
mongoc_client_t * client ;
2315
2315
char * hello ;
2316
+ char * hello_not_ok ;
2316
2317
future_t * future ;
2317
2318
request_t * request ;
2318
2319
bson_error_t error ;
@@ -2338,6 +2339,14 @@ _test_hello_ok (bool pooled)
2338
2339
" 'hosts': ['%s']}" ,
2339
2340
mock_server_get_host_and_port (server ));
2340
2341
2342
+ hello_not_ok = bson_strdup_printf ("{'ok': 1,"
2343
+ " 'isWritablePrimary': true,"
2344
+ " 'setName': 'rs',"
2345
+ " 'minWireVersion': 2,"
2346
+ " 'maxWireVersion': 5,"
2347
+ " 'hosts': ['%s']}" ,
2348
+ mock_server_get_host_and_port (server ));
2349
+
2341
2350
/* For client pools, the first handshake happens when the client is popped.
2342
2351
* For non-pooled clients, send a ping command to trigger a handshake. */
2343
2352
if (!pooled ) {
@@ -2366,9 +2375,40 @@ _test_hello_ok (bool pooled)
2366
2375
client , "admin" , tmp_bson ("{'ping': 1}" ), NULL , NULL , & error );
2367
2376
}
2368
2377
2378
+ /* Hang up to ensure that the next check runs legacy hello again */
2369
2379
request = mock_server_receives_hello (server );
2370
2380
BSON_ASSERT (request );
2371
- mock_server_replies_simple (request , hello );
2381
+ mock_server_hangs_up (request );
2382
+ request_destroy (request );
2383
+
2384
+ /* The previous failure will trigger another handshake using legacy hello */
2385
+ request = mock_server_receives_legacy_hello (
2386
+ server , "{'" HANDSHAKE_CMD_LEGACY_HELLO "': 1, 'helloOk': true}" );
2387
+ BSON_ASSERT (request );
2388
+ mock_server_replies_simple (request , hello_not_ok );
2389
+ request_destroy (request );
2390
+
2391
+ /* Once again, handle the ping */
2392
+ if (!pooled ) {
2393
+ request = mock_server_receives_command (
2394
+ server , "admin" , MONGOC_QUERY_SECONDARY_OK , "{'ping': 1}" );
2395
+ mock_server_replies_ok_and_destroys (request );
2396
+ BSON_ASSERT (future_get_bool (future ));
2397
+ future_destroy (future );
2398
+
2399
+ /* Send off another ping for non-pooled clients, making sure to wait long
2400
+ * enough to require another heartbeat. */
2401
+ _mongoc_usleep (600 * 1000 );
2402
+ future = future_client_command_simple (
2403
+ client , "admin" , tmp_bson ("{'ping': 1}" ), NULL , NULL , & error );
2404
+ }
2405
+
2406
+ /* Since we never responded with helloOk: true, we're expecting another
2407
+ * legacy hello. */
2408
+ request = mock_server_receives_legacy_hello (
2409
+ server , "{'" HANDSHAKE_CMD_LEGACY_HELLO "': 1, 'helloOk': true}" );
2410
+ BSON_ASSERT (request );
2411
+ mock_server_replies_simple (request , hello_not_ok );
2372
2412
request_destroy (request );
2373
2413
2374
2414
/* Once again, handle the ping */
@@ -2390,6 +2430,7 @@ _test_hello_ok (bool pooled)
2390
2430
mongoc_uri_destroy (uri );
2391
2431
mock_server_destroy (server );
2392
2432
bson_free (hello );
2433
+ bson_free (hello_not_ok );
2393
2434
}
2394
2435
2395
2436
static void
0 commit comments