@@ -88,7 +88,9 @@ topology_closed (const mongoc_apm_topology_closed_t *event)
88
88
context -> topology_closed_events ++ ;
89
89
}
90
90
91
- static mongoc_apm_callbacks_t * make_callbacks (void ) {
91
+ static mongoc_apm_callbacks_t *
92
+ make_callbacks (void )
93
+ {
92
94
mongoc_apm_callbacks_t * cbs ;
93
95
94
96
cbs = mongoc_apm_callbacks_new ();
@@ -101,7 +103,9 @@ static mongoc_apm_callbacks_t * make_callbacks (void) {
101
103
return cbs ;
102
104
}
103
105
104
- static stats_t * set_client_callbacks (mongoc_client_t * client ) {
106
+ static stats_t *
107
+ set_client_callbacks (mongoc_client_t * client )
108
+ {
105
109
mongoc_apm_callbacks_t * cbs ;
106
110
stats_t * stats ;
107
111
@@ -112,7 +116,9 @@ static stats_t * set_client_callbacks (mongoc_client_t *client) {
112
116
return stats ;
113
117
}
114
118
115
- static stats_t * set_client_pool_callbacks (mongoc_client_pool_t * pool ) {
119
+ static stats_t *
120
+ set_client_pool_callbacks (mongoc_client_pool_t * pool )
121
+ {
116
122
mongoc_apm_callbacks_t * cbs ;
117
123
stats_t * stats ;
118
124
@@ -123,7 +129,9 @@ static stats_t * set_client_pool_callbacks (mongoc_client_pool_t *pool) {
123
129
return stats ;
124
130
}
125
131
126
- static void free_and_assert_stats (stats_t * stats ) {
132
+ static void
133
+ free_and_assert_stats (stats_t * stats )
134
+ {
127
135
ASSERT_CMPINT (stats -> topology_opening_events , = = , 1 );
128
136
ASSERT_CMPINT (stats -> topology_changed_events , = = , 2 );
129
137
ASSERT_CMPINT (stats -> server_opening_events , = = , 1 );
@@ -267,7 +275,8 @@ test_loadbalanced_connect_single (void *unused)
267
275
& error );
268
276
ASSERT_OR_PRINT (ok , error );
269
277
270
- /* Ensure the server description is unchanged and remains as type LoadBalancer. */
278
+ /* Ensure the server description is unchanged and remains as type
279
+ * LoadBalancer. */
271
280
monitor_sd = mongoc_client_select_server (
272
281
client , true /* for writes */ , NULL /* read prefs */ , & error );
273
282
ASSERT_OR_PRINT (monitor_sd , error );
@@ -298,14 +307,15 @@ test_loadbalanced_connect_pooled (void *unused)
298
307
client = mongoc_client_pool_pop (pool );
299
308
300
309
ok = mongoc_client_command_simple (client ,
301
- "admin" ,
302
- tmp_bson ("{'ping': 1}" ),
303
- NULL /* read prefs */ ,
304
- NULL /* reply */ ,
305
- & error );
310
+ "admin" ,
311
+ tmp_bson ("{'ping': 1}" ),
312
+ NULL /* read prefs */ ,
313
+ NULL /* reply */ ,
314
+ & error );
306
315
ASSERT_OR_PRINT (ok , error );
307
316
308
- /* Ensure the server description is unchanged and remains as type LoadBalancer. */
317
+ /* Ensure the server description is unchanged and remains as type
318
+ * LoadBalancer. */
309
319
monitor_sd = mongoc_client_select_server (
310
320
client , true /* for writes */ , NULL /* read prefs */ , & error );
311
321
ASSERT_OR_PRINT (monitor_sd , error );
@@ -316,7 +326,7 @@ test_loadbalanced_connect_pooled (void *unused)
316
326
mongoc_uri_destroy (uri );
317
327
mongoc_client_pool_push (pool , client );
318
328
mongoc_client_pool_destroy (pool );
319
- free_and_assert_stats (stats );
329
+ free_and_assert_stats (stats );
320
330
}
321
331
322
332
/* Ensure that server selection on single threaded clients establishes a
@@ -349,10 +359,76 @@ test_loadbalanced_server_selection_establishes_connection_single (void *unused)
349
359
mongoc_client_destroy (client );
350
360
}
351
361
352
- /* Test that the 5 second cooldown does not apply when establishing a new connection to the load balancer after a network error. */
362
+ /* Test that the 5 second cooldown does not apply when establishing a new
363
+ * connection to the load balancer after a network error. */
353
364
static void
354
- test_loadbalanced_network_error_bypasses_cooldown_single (void * unused ) {
365
+ test_loadbalanced_cooldown_is_bypassed_single (void * unused )
366
+ {
367
+ mongoc_client_t * client ;
368
+ char * uristr = loadbalanced_uri ();
369
+ bson_error_t error ;
370
+ bool ok ;
371
+ stats_t * stats ;
372
+ mongoc_server_description_t * monitor_sd ;
373
+
374
+ client = mongoc_client_new (uristr );
375
+ stats = set_client_callbacks (client );
376
+
377
+ ok = mongoc_client_command_simple (
378
+ client ,
379
+ "admin" ,
380
+ tmp_bson ("{'configureFailPoint': 'failCommand', 'mode': { 'times': 2 }, "
381
+ "'data': {'closeConnection': true, 'failCommands': ['ping', "
382
+ "'isMaster']}}" ),
383
+ NULL /* read prefs */ ,
384
+ NULL /* reply */ ,
385
+ & error );
386
+ ASSERT_OR_PRINT (ok , error );
387
+
388
+ ok = mongoc_client_command_simple (client ,
389
+ "admin" ,
390
+ tmp_bson ("{'ping': 1}" ),
391
+ NULL /* read prefs */ ,
392
+ NULL /* reply */ ,
393
+ & error );
394
+ ASSERT_ERROR_CONTAINS (
395
+ error , MONGOC_ERROR_STREAM , MONGOC_ERROR_STREAM_SOCKET , "socket error" );
355
396
397
+ /* The next attempted command should attempt to scan, and fail when
398
+ * performing the handshake with the isMaster command. */
399
+ ok = mongoc_client_command_simple (client ,
400
+ "admin" ,
401
+ tmp_bson ("{'ping': 1}" ),
402
+ NULL /* read prefs */ ,
403
+ NULL /* reply */ ,
404
+ & error );
405
+ ASSERT_ERROR_CONTAINS (error ,
406
+ MONGOC_ERROR_STREAM ,
407
+ MONGOC_ERROR_STREAM_NOT_ESTABLISHED ,
408
+ "Could not establish stream" );
409
+
410
+ /* Failing to "scan" would normally cause the node to be in cooldown. But in
411
+ * load balancer mode this is bypassed. The subsequent connect attempt should
412
+ * succeed. */
413
+ ok = mongoc_client_command_simple (client ,
414
+ "admin" ,
415
+ tmp_bson ("{'ping': 1}" ),
416
+ NULL /* read prefs */ ,
417
+ NULL /* reply */ ,
418
+ & error );
419
+ ASSERT_OR_PRINT (ok , error );
420
+
421
+ /* Ensure the server description is unchanged and remains as type
422
+ * LoadBalancer. */
423
+ monitor_sd = mongoc_client_select_server (
424
+ client , true /* for writes */ , NULL /* read prefs */ , & error );
425
+ ASSERT_OR_PRINT (monitor_sd , error );
426
+ ASSERT_CMPSTR ("LoadBalancer" , mongoc_server_description_type (monitor_sd ));
427
+
428
+ mongoc_server_description_destroy (monitor_sd );
429
+ bson_free (uristr );
430
+ mongoc_client_destroy (client );
431
+ free_and_assert_stats (stats );
356
432
}
357
433
358
434
static int
@@ -409,4 +485,12 @@ test_loadbalanced_install (TestSuite *suite)
409
485
NULL /* ctx */ ,
410
486
NULL /* dtor */ ,
411
487
skip_if_not_loadbalanced );
488
+
489
+ TestSuite_AddFull (suite ,
490
+ "/loadbalanced/cooldown_is_bypassed/single" ,
491
+ test_loadbalanced_cooldown_is_bypassed_single ,
492
+ NULL /* dtor */ ,
493
+ NULL /* ctx */ ,
494
+ skip_if_not_loadbalanced ,
495
+ test_framework_skip_if_no_failpoint );
412
496
}
0 commit comments