Skip to content

Commit 5452e1e

Browse files
beltranmambocab
authored andcommitted
Add test PYTHON-973
1 parent 662e12f commit 5452e1e

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

tests/integration/standard/test_connection.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
requiresmallclockgranularity, greaterthancass20
3939
try:
4040
from cassandra.io.libevreactor import LibevConnection
41+
import cassandra.io.libevreactor
4142
except ImportError:
4243
LibevConnection = None
4344

@@ -392,26 +393,13 @@ def test_connect_timeout(self):
392393
break
393394
self.assertTrue(exception_thrown)
394395

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-
405396
def test_subclasses_share_loop(self):
406397
class C1(AsyncoreConnection):
407398
pass
408399

409400
class C2(AsyncoreConnection):
410401
pass
411402

412-
cassandra.io.asyncorereactor._global_loop._cleanup()
413-
cassandra.io.asyncorereactor._global_loop = None
414-
415403
clusterC1 = Cluster(connection_class=C1)
416404
clusterC1.connect(wait_for_all_pools=True)
417405

@@ -420,14 +408,35 @@ class C2(AsyncoreConnection):
420408
self.addCleanup(clusterC1.shutdown)
421409
self.addCleanup(clusterC2.shutdown)
422410

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
426434

427435

428436
class LibevConnectionTests(ConnectionTests, unittest.TestCase):
429437

430438
klass = LibevConnection
439+
event_loop_name = "event_loop"
431440

432441
def setUp(self):
433442
if is_monkey_patched():
@@ -436,3 +445,7 @@ def setUp(self):
436445
raise unittest.SkipTest(
437446
'libev does not appear to be installed properly')
438447
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

Comments
 (0)