Skip to content

Commit d31ea37

Browse files
mykauldkropachev
authored andcommitted
tests: replace fixed time.sleep() calls with polling (~17s saving)
- test_cluster.py: replace sleep(1) x10 iterations with connect(wait_for_all_pools=True) for deterministic pool readiness - test_query.py: replace sleep(5) with wait_until polling for 'Preparing all known prepared statements' log message - test_connection.py: replace sleep(2) with wait_until polling for host_down listener notification
1 parent 9fe9931 commit d31ea37

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

tests/integration/standard/test_cluster.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,8 +1121,7 @@ def test_stale_connections_after_shutdown(self):
11211121
"""
11221122
for _ in range(10):
11231123
with TestCluster(protocol_version=3) as cluster:
1124-
cluster.connect().execute("SELECT * FROM system_schema.keyspaces")
1125-
time.sleep(1)
1124+
cluster.connect(wait_for_all_pools=True).execute("SELECT * FROM system_schema.keyspaces")
11261125

11271126
with TestCluster(protocol_version=3) as cluster:
11281127
session = cluster.connect()

tests/integration/standard/test_connection.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from tests import is_monkey_patched
3333
from tests.integration import use_singledc, get_node, CASSANDRA_IP, local, \
3434
requiresmallclockgranularity, greaterthancass20, TestCluster
35+
from tests.util import wait_until
3536

3637
try:
3738
import cassandra.io.asyncorereactor
@@ -140,9 +141,10 @@ def test_heart_beat_timeout(self):
140141
# Wait for connections associated with this host go away
141142
self.wait_for_no_connections(host, self.cluster)
142143

143-
# Wait to seconds for the driver to be notified
144-
time.sleep(2)
145-
assert test_listener.host_down
144+
# Wait for the driver to detect the host is down
145+
wait_until(
146+
lambda: test_listener.host_down,
147+
delay=0.5, max_attempts=20)
146148
# Resume paused node
147149
finally:
148150
node.resume()

tests/integration/standard/test_query.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
USE_CASS_EXTERNAL, greaterthanorequalcass40, TestCluster, xfail_scylla
3030
from tests import notwindows
3131
from tests.integration import greaterthanorequalcass30, get_node
32-
from tests.util import assertListEqual
32+
from tests.util import assertListEqual, wait_until
3333

3434
import time
3535
import random
@@ -1571,9 +1571,10 @@ def test_reprepare_after_host_is_down(self):
15711571

15721572
get_node(1).start(wait_for_binary_proto=True, wait_other_notice=True)
15731573

1574-
# We wait for cluster._prepare_all_queries to be called
1575-
time.sleep(5)
1576-
assert 1 == mock_handler.get_message_count('debug', 'Preparing all known prepared statements')
1574+
# Wait for cluster._prepare_all_queries to be called
1575+
wait_until(
1576+
lambda: mock_handler.get_message_count('debug', 'Preparing all known prepared statements') >= 1,
1577+
delay=0.5, max_attempts=20)
15771578

15781579
results = self.session.execute(prepared_statement, (1,), execution_profile="only_first")
15791580
assert results.one() == (1, )

0 commit comments

Comments
 (0)