Skip to content

Commit dd19725

Browse files
committed
Longer timeout in connectTimeout test.
1 parent 6553057 commit dd19725

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tests/test-mongoc-topology.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ test_cooldown_rs (void)
556556
static void
557557
_test_connect_timeout (bool pooled, bool try_once)
558558
{
559-
const int32_t connect_timeout_ms = 50;
559+
const int32_t connect_timeout_ms = 200;
560560
const int32_t server_selection_timeout_ms = 10 * 1000; /* 10 seconds */
561561

562562
mock_server_t *servers[2];
@@ -569,10 +569,12 @@ _test_connect_timeout (bool pooled, bool try_once)
569569
mongoc_read_prefs_t *primary_pref;
570570
future_t *future;
571571
int64_t start;
572+
int64_t server0_last_ismaster;
572573
int64_t duration_usec;
574+
int64_t expected_duration_usec;
575+
bool server0_in_cooldown;
573576
bson_error_t error;
574577
request_t *request;
575-
int n_loops;
576578

577579
assert (!(pooled && try_once)); /* not supported */
578580

@@ -615,7 +617,7 @@ _test_connect_timeout (bool pooled, bool try_once)
615617
future = future_topology_select (client->topology, MONGOC_SS_READ,
616618
primary_pref, 15, &error);
617619

618-
start = bson_get_monotonic_time ();
620+
server0_last_ismaster = start = bson_get_monotonic_time ();
619621

620622
/* server 0 doesn't respond */
621623
assert (request = mock_server_receives_ismaster (servers[0]));
@@ -628,22 +630,30 @@ _test_connect_timeout (bool pooled, bool try_once)
628630

629631
if (!try_once) {
630632
/* driver retries every minHeartbeatFrequencyMS + connectTimeoutMS */
631-
n_loops = server_selection_timeout_ms / (500 + connect_timeout_ms);
633+
server0_in_cooldown = true;
634+
expected_duration_usec = 0;
632635

633-
for (i = 1; i <= n_loops; i++) {
636+
while (expected_duration_usec < server_selection_timeout_ms) {
634637
request = mock_server_receives_ismaster (servers[1]);
635638
mock_server_replies_simple (request, secondary_response);
636639
request_destroy (request);
637640

638641
duration_usec = bson_get_monotonic_time () - start;
639-
ASSERT_ALMOST_EQUAL (duration_usec / 1000,
640-
i * (500 + connect_timeout_ms));
642+
expected_duration_usec += 1000 * (
643+
connect_timeout_ms + MONGOC_TOPOLOGY_MIN_HEARTBEAT_FREQUENCY_MS);
644+
645+
ASSERT_ALMOST_EQUAL (duration_usec, expected_duration_usec);
641646

642647
/* single client puts server 0 in cooldown for 5 sec */
643-
if (pooled || i == 10) {
648+
if (pooled || !server0_in_cooldown) {
644649
assert (request = mock_server_receives_ismaster (servers[0]));
650+
server0_last_ismaster = bson_get_monotonic_time ();
645651
request_destroy (request); /* don't respond */
646652
}
653+
654+
server0_in_cooldown =
655+
(bson_get_monotonic_time () - server0_last_ismaster) <
656+
5 * 1000 * 1000;
647657
}
648658
}
649659

0 commit comments

Comments
 (0)