38
38
requiresmallclockgranularity , greaterthancass20
39
39
try :
40
40
from cassandra .io .libevreactor import LibevConnection
41
+ import cassandra .io .libevreactor
41
42
except ImportError :
42
43
LibevConnection = None
43
44
@@ -392,26 +393,13 @@ def test_connect_timeout(self):
392
393
break
393
394
self .assertTrue (exception_thrown )
394
395
395
-
396
- class AsyncoreConnectionTests (ConnectionTests , unittest .TestCase ):
397
-
398
- klass = AsyncoreConnection
399
-
400
- def setUp (self ):
401
- if is_monkey_patched ():
402
- raise unittest .SkipTest ("Can't test asyncore with monkey patching" )
403
- ConnectionTests .setUp (self )
404
-
405
396
def test_subclasses_share_loop (self ):
406
397
class C1 (AsyncoreConnection ):
407
398
pass
408
399
409
400
class C2 (AsyncoreConnection ):
410
401
pass
411
402
412
- cassandra .io .asyncorereactor ._global_loop ._cleanup ()
413
- cassandra .io .asyncorereactor ._global_loop = None
414
-
415
403
clusterC1 = Cluster (connection_class = C1 )
416
404
clusterC1 .connect (wait_for_all_pools = True )
417
405
@@ -420,14 +408,35 @@ class C2(AsyncoreConnection):
420
408
self .addCleanup (clusterC1 .shutdown )
421
409
self .addCleanup (clusterC2 .shutdown )
422
410
423
- event_loops_threads = [thread for thread in threading .enumerate () if
424
- thread .name == "cassandra_driver_event_loop" ]
425
- self .assertEqual (len (event_loops_threads ), 1 )
411
+ self .assertEqual (len (get_eventloop_threads (self .event_loop_name )), 1 )
412
+
413
+
414
+ def get_eventloop_threads (name ):
415
+ import threading
416
+ event_loops_threads = [thread for thread in threading .enumerate () if name == thread .name ]
417
+
418
+ return event_loops_threads
419
+
420
+
421
+ class AsyncoreConnectionTests (ConnectionTests , unittest .TestCase ):
422
+
423
+ klass = AsyncoreConnection
424
+ event_loop_name = "cassandra_driver_event_loop"
425
+
426
+ def setUp (self ):
427
+ if is_monkey_patched ():
428
+ raise unittest .SkipTest ("Can't test asyncore with monkey patching" )
429
+ ConnectionTests .setUp (self )
430
+
431
+ def clean_global_loop (self ):
432
+ cassandra .io .asyncorereactor ._global_loop ._cleanup ()
433
+ cassandra .io .asyncorereactor ._global_loop = None
426
434
427
435
428
436
class LibevConnectionTests (ConnectionTests , unittest .TestCase ):
429
437
430
438
klass = LibevConnection
439
+ event_loop_name = "event_loop"
431
440
432
441
def setUp (self ):
433
442
if is_monkey_patched ():
@@ -436,3 +445,7 @@ def setUp(self):
436
445
raise unittest .SkipTest (
437
446
'libev does not appear to be installed properly' )
438
447
ConnectionTests .setUp (self )
448
+
449
+ def clean_global_loop (self ):
450
+ cassandra .io .libevreactor ._global_loop ._cleanup ()
451
+ cassandra .io .libevreactor ._global_loop = None
0 commit comments