Skip to content

Commit 232058c

Browse files
committed
ConnectionHeartbeat test_empty_connection: make sure the thread is started before starting the test delay
1 parent 2e33c9c commit 232058c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/unit/test_connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from cassandra.protocol import (write_stringmultimap, write_int, write_string,
3232
SupportedMessage, ProtocolHandler)
3333

34+
from tests.integration.util import wait_until
35+
3436

3537
class ConnectionTest(unittest.TestCase):
3638

@@ -284,7 +286,9 @@ def make_get_holders(len):
284286

285287
def run_heartbeat(self, get_holders_fun, count=2, interval=0.05, timeout=0.05):
286288
ch = ConnectionHeartbeat(interval, get_holders_fun, timeout=timeout)
287-
time.sleep(interval * count)
289+
# wait until the thread is started
290+
wait_until(lambda: get_holders_fun.call_count > 0, 0.01, 100)
291+
time.sleep(interval * (count-1))
288292
ch.stop()
289293
self.assertTrue(get_holders_fun.call_count)
290294

@@ -294,7 +298,7 @@ def test_empty_connections(self, *args):
294298

295299
self.run_heartbeat(get_holders, count)
296300

297-
self.assertGreaterEqual(get_holders.call_count, count - 1) # lower bound to account for thread spinup time
301+
self.assertGreaterEqual(get_holders.call_count, count-1)
298302
self.assertLessEqual(get_holders.call_count, count)
299303
holder = get_holders.return_value[0]
300304
holder.get_connections.assert_has_calls([call()] * get_holders.call_count)

0 commit comments

Comments
 (0)