31
31
from cassandra .protocol import (write_stringmultimap , write_int , write_string ,
32
32
SupportedMessage , ProtocolHandler )
33
33
34
+ from tests .integration .util import wait_until
35
+
34
36
35
37
class ConnectionTest (unittest .TestCase ):
36
38
@@ -284,7 +286,9 @@ def make_get_holders(len):
284
286
285
287
def run_heartbeat (self , get_holders_fun , count = 2 , interval = 0.05 , timeout = 0.05 ):
286
288
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 ))
288
292
ch .stop ()
289
293
self .assertTrue (get_holders_fun .call_count )
290
294
@@ -294,7 +298,7 @@ def test_empty_connections(self, *args):
294
298
295
299
self .run_heartbeat (get_holders , count )
296
300
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 )
298
302
self .assertLessEqual (get_holders .call_count , count )
299
303
holder = get_holders .return_value [0 ]
300
304
holder .get_connections .assert_has_calls ([call ()] * get_holders .call_count )
0 commit comments