Skip to content

Commit f7aa22b

Browse files
committed
1
1 parent c436ab0 commit f7aa22b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/unit/test_shard_aware.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,19 @@ def mock_connection_factory(self, *args, **kwargs):
138138
assert connection.endpoint == DefaultEndPoint("1.2.3.4", port=port)
139139

140140
sleep_time = 0
141-
schedule = reconnection_policy.new_schedule()
142-
for _ in range(shard_count+1):
143-
sleep_time += next(schedule)
144-
145-
if sleep_time > 0:
146-
time.sleep(sleep_time)
141+
if reconnection_policy:
142+
# Check that connections to shards are being established according to the policy
143+
# Calculate total time it will need to establish all connections
144+
# Sleep half of the time and check that connections are not there yet
145+
# Sleep rest of the time + 1 second and check that all connections has been established
146+
schedule = reconnection_policy.new_schedule()
147+
for _ in range(shard_count):
148+
sleep_time += next(schedule)
149+
if sleep_time > 0:
150+
time.sleep(sleep_time/2)
151+
# Check that connection are not being established quicker than expected
152+
assert len(pool._connections) < expected_after
153+
time.sleep(sleep_time/2 + 1)
147154

148155
assert len(pool._connections) == expected_after
149156
finally:

0 commit comments

Comments
 (0)