1616except ImportError :
1717 import unittest # noqa
1818
19- import time
2019import logging
20+ import time
2121
22- from cassandra import OperationTimedOut
23- from cassandra .cluster import Cluster , _Scheduler , EXEC_PROFILE_DEFAULT , ExecutionProfile
24- from cassandra .policies import RoundRobinPolicy , HostStateListener
2522from concurrent .futures import ThreadPoolExecutor
2623
27- from tests .integration import ifsimulacron , CASSANDRA_VERSION
28- from tests .integration .simulacron .utils import start_and_prime_cluster_defaults , prime_query , stop_simulacron , \
29- prime_request , PrimeOptions , NO_THEN
24+ from cassandra import OperationTimedOut
25+ from cassandra .cluster import (EXEC_PROFILE_DEFAULT , Cluster , ExecutionProfile ,
26+ _Scheduler )
27+ from cassandra .policies import HostStateListener , RoundRobinPolicy
28+ from tests .integration import CASSANDRA_VERSION , requiressimulacron
29+ from tests .integration .simulacron .utils import (NO_THEN , PrimeOptions ,
30+ prime_query , prime_request ,
31+ start_and_prime_cluster_defaults ,
32+ stop_simulacron )
3033
31- import time
3234
3335class TrackDownListener (HostStateListener ):
3436 hosts_marked_down = []
@@ -43,7 +45,7 @@ def submit(self, fn, *args, **kwargs):
4345 self .called_functions .append (fn .__name__ )
4446 return super (ThreadTracker , self ).submit (fn , * args , ** kwargs )
4547
46- @ifsimulacron
48+ @requiressimulacron
4749class ConnectionTest (unittest .TestCase ):
4850
4951 def test_heart_beat_timeout (self ):
@@ -65,6 +67,7 @@ def test_heart_beat_timeout(self):
6567 idle_heartbeat_interval = 1
6668
6769 start_and_prime_cluster_defaults (number_of_dcs , nodes_per_dc , CASSANDRA_VERSION )
70+ self .addCleanup (stop_simulacron )
6871
6972 listener = TrackDownListener ()
7073 executor = ThreadTracker (max_workers = 16 )
@@ -76,18 +79,17 @@ def test_heart_beat_timeout(self):
7679 executor_threads = 16 ,
7780 execution_profiles = {
7881 EXEC_PROFILE_DEFAULT : ExecutionProfile (load_balancing_policy = RoundRobinPolicy ())})
82+ self .addCleanup (cluster .shutdown )
7983
8084 cluster .scheduler .shutdown ()
8185 cluster .executor = executor
8286 cluster .scheduler = _Scheduler (executor )
8387
8488 session = cluster .connect (wait_for_all_pools = True )
8589 cluster .register_listener (listener )
90+
8691 log = logging .getLogger ()
8792 log .setLevel ('CRITICAL' )
88-
89- self .addCleanup (cluster .shutdown )
90- self .addCleanup (stop_simulacron )
9193 self .addCleanup (log .setLevel , "DEBUG" )
9294
9395 prime_query (query_to_prime , then = NO_THEN )
@@ -105,7 +107,7 @@ def test_heart_beat_timeout(self):
105107
106108 # We allow from some extra time for all the hosts to be to on_down
107109 # The callbacks should start happening after idle_heartbeat_timeout + idle_heartbeat_interval
108- time .sleep ((idle_heartbeat_timeout + idle_heartbeat_interval )* 2 )
110+ time .sleep ((idle_heartbeat_timeout + idle_heartbeat_interval ) * 2 )
109111
110112 for host in cluster .metadata .all_hosts ():
111113 self .assertIn (host , listener .hosts_marked_down )
0 commit comments