Skip to content

Commit e0e003f

Browse files
authored
Merge pull request datastax#972 from datastax/python-fix-master-loop-tests
Python fix master loop tests
2 parents 5bd1cea + 1dcc85a commit e0e003f

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

cassandra/io/asyncorereactor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def maybe_start(self):
237237
self._loop_lock.release()
238238

239239
if should_start:
240-
self._thread = Thread(target=self._run_loop, name="cassandra_driver_event_loop")
240+
self._thread = Thread(target=self._run_loop, name="asyncore_cassandra_driver_event_loop")
241241
self._thread.daemon = True
242242
self._thread.start()
243243

cassandra/io/twistedreactor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def maybe_start(self):
128128
with self._lock:
129129
if not reactor.running:
130130
self._thread = Thread(target=reactor.run,
131-
name="cassandra_driver_event_loop",
131+
name="cassandra_driver_twisted_event_loop",
132132
kwargs={'installSignalHandlers': False})
133133
self._thread.daemon = True
134134
self._thread.start()

tests/integration/standard/test_connection.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import unittest # noqa
1919

2020
from functools import partial
21+
import logging
2122
from six.moves import range
2223
import sys
2324
import threading
2425
from threading import Thread, Event
2526
import time
27+
from unittest import SkipTest
2628

2729
from cassandra import ConsistencyLevel, OperationTimedOut
2830
from cassandra.cluster import NoHostAvailable, ConnectionShutdown, Cluster
@@ -43,6 +45,9 @@
4345
LibevConnection = None
4446

4547

48+
log = logging.getLogger(__name__)
49+
50+
4651
def setup_module():
4752
use_singledc()
4853

@@ -394,10 +399,14 @@ def test_connect_timeout(self):
394399
self.assertTrue(exception_thrown)
395400

396401
def test_subclasses_share_loop(self):
397-
class C1(AsyncoreConnection):
402+
403+
if self.klass not in (AsyncoreConnection, LibevConnection):
404+
raise SkipTest
405+
406+
class C1(self.klass):
398407
pass
399408

400-
class C2(AsyncoreConnection):
409+
class C2(self.klass):
401410
pass
402411

403412
clusterC1 = Cluster(connection_class=C1)
@@ -412,16 +421,18 @@ class C2(AsyncoreConnection):
412421

413422

414423
def get_eventloop_threads(name):
415-
import threading
416-
event_loops_threads = [thread for thread in threading.enumerate() if name == thread.name]
424+
all_threads = list(threading.enumerate())
425+
log.debug('all threads: {}'.format(all_threads))
426+
log.debug('all names: {}'.format([thread.name for thread in all_threads]))
427+
event_loops_threads = [thread for thread in all_threads if name == thread.name]
417428

418429
return event_loops_threads
419430

420431

421432
class AsyncoreConnectionTests(ConnectionTests, unittest.TestCase):
422433

423434
klass = AsyncoreConnection
424-
event_loop_name = "cassandra_driver_event_loop"
435+
event_loop_name = "asyncore_cassandra_driver_event_loop"
425436

426437
def setUp(self):
427438
if is_monkey_patched():

tests/unit/io/test_asyncioreactor.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
1-
21
try:
32
from cassandra.io.asyncioreactor import AsyncioConnection
43
import asynctest
54
ASYNCIO_AVAILABLE = True
65
except (ImportError, SyntaxError):
6+
AysncioConnection = None
77
ASYNCIO_AVAILABLE = False
88

9-
from tests import is_monkey_patched
9+
from tests import is_monkey_patched, connection_class
1010
from tests.unit.io.utils import TimerCallback, TimerTestMixin
1111

1212
from mock import patch
1313

1414
import unittest
1515
import time
1616

17+
skip_me = (is_monkey_patched() or
18+
(not ASYNCIO_AVAILABLE) or
19+
(connection_class is not AsyncioConnection))
20+
1721

22+
@unittest.skipIf(is_monkey_patched(), 'runtime is monkey patched for another reactor')
23+
@unittest.skipIf(connection_class is not AsyncioConnection,
24+
'not running asyncio tests; current connection_class is {}'.format(connection_class))
1825
@unittest.skipUnless(ASYNCIO_AVAILABLE, "asyncio is not available for this runtime")
1926
class AsyncioTimerTests(TimerTestMixin, unittest.TestCase):
2027

2128
@classmethod
2229
def setUpClass(cls):
23-
if is_monkey_patched() or not ASYNCIO_AVAILABLE:
30+
if skip_me:
2431
return
2532
cls.connection_class = AsyncioConnection
2633
AsyncioConnection.initialize_reactor()
2734

2835
@classmethod
2936
def tearDownClass(cls):
30-
if ASYNCIO_AVAILABLE:
37+
if skip_me:
38+
return
39+
if ASYNCIO_AVAILABLE and AsyncioConnection._loop:
3140
AsyncioConnection._loop.stop()
3241

3342
@property
@@ -39,6 +48,8 @@ def _timers(self):
3948
raise RuntimeError('no TimerManager for AsyncioConnection')
4049

4150
def setUp(self):
51+
if skip_me:
52+
return
4253
socket_patcher = patch('socket.socket')
4354
self.addCleanup(socket_patcher.stop)
4455
socket_patcher.start()

0 commit comments

Comments
 (0)