Acknowledge the some review comments for tests

This commit is contained in:
bjmb
2017-04-06 15:09:10 -04:00
parent 722d8455de
commit 9848ef3987
6 changed files with 32 additions and 37 deletions

View File

@@ -59,8 +59,8 @@ def is_monkey_patched():
return is_gevent_monkey_patched() or is_eventlet_monkey_patched() return is_gevent_monkey_patched() or is_eventlet_monkey_patched()
MONKEY_PATCH_LOOP = bool(os.getenv('MONKEY_PATCH_LOOP', False)) MONKEY_PATCH_LOOP = bool(os.getenv('MONKEY_PATCH_LOOP', False) == "1")
notwindows = unittest.skipUnless(not "Windows" in platform.system(), "This test is not adequate for windows") notwindows = unittest.skipUnless(not "Windows" in platform.system(), "This test is not adequate for windows")
notpypy = unittest.skipUnless(not '__pypy__' in sys.builtin_module_names, "This tests is not suitable for pypy") notpypy = unittest.skipUnless(not platform.python_implementation() == 'PyPy', "This tests is not suitable for pypy")
notmonkeypatch = unittest.skipUnless(MONKEY_PATCH_LOOP, "Skpping this test because monkey patching is required") notmonkeypatch = unittest.skipUnless(MONKEY_PATCH_LOOP, "Skpping this test because monkey patching is required")

View File

@@ -20,10 +20,11 @@ try:
import thread import thread
import Queue import Queue
import __builtin__ import __builtin__
except: #For python3 compatibility
except ImportError:
import _thread as thread import _thread as thread
import queue as Queue import queue as Queue
import builtins import builtins as __builtin__
import threading import threading
import ssl import ssl

View File

@@ -19,34 +19,31 @@ except ImportError:
import unittest # noqa import unittest # noqa
from tests.unit.io.utils import TimerConnectionTests from tests.unit.io.utils import TimerConnectionTests
from tests.unit.io.eventlet_utils import restore_saved_module, eventlet_un_patch_all from tests.unit.io.eventlet_utils import restore_saved_module
from tests import notpypy, MONKEY_PATCH_LOOP from tests import notpypy
from tests import notmonkeypatch
import time import time
from eventlet import monkey_patch, kill from eventlet import monkey_patch, kill
import threading
try: try:
from cassandra.io.eventletreactor import EventletConnection from cassandra.io.eventletreactor import EventletConnection
except ImportError: except ImportError:
EventletConnection = None # noqa EventletConnection = None # noqa
@unittest.skipUnless(EventletConnection is not None, "Skpping the eventlet tests because it's not installed")
@notmonkeypatch
# There are some issues with some versions of pypy and eventlet
@notpypy
class EventletTimerTest(unittest.TestCase, TimerConnectionTests): class EventletTimerTest(unittest.TestCase, TimerConnectionTests):
# There are some issues with some versions of pypy and eventlet
@notpypy
def setUp(self): def setUp(self):
if not MONKEY_PATCH_LOOP: self.connection_class = EventletConnection
raise unittest.SkipTest("Skpping because monkey patching may affect the rest of the tests") # We only to patch the time module
monkey_patch(time=True)
if not EventletConnection:
raise unittest.SkipTest("Can't test eventlet without monkey patching")
monkey_patch(thread=False, time=True)
EventletConnection.initialize_reactor() EventletConnection.initialize_reactor()
def tearDown(self): def tearDown(self):
kill(EventletConnection._timeout_watcher) kill(EventletConnection._timeout_watcher)
EventletConnection._timers = None EventletConnection._timers = None
restore_saved_module(time) restore_saved_module(time)
def getClass(self):
return EventletConnection

View File

@@ -19,8 +19,7 @@ except ImportError:
from tests.unit.io.utils import TimerConnectionTests from tests.unit.io.utils import TimerConnectionTests
from tests import MONKEY_PATCH_LOOP from tests import notmonkeypatch
try: try:
from cassandra.io.geventreactor import GeventConnection from cassandra.io.geventreactor import GeventConnection
import gevent.monkey import gevent.monkey
@@ -28,20 +27,16 @@ try:
except ImportError: except ImportError:
GeventConnection = None # noqa GeventConnection = None # noqa
@unittest.skipUnless(GeventConnection is not None, "Skpping the gevent tests because it's not installed")
@notmonkeypatch
class GeventTimerTest(unittest.TestCase, TimerConnectionTests): class GeventTimerTest(unittest.TestCase, TimerConnectionTests):
def setUp(self):
if not MONKEY_PATCH_LOOP:
raise unittest.SkipTest("Skpping because monkey patching may affect the rest of the tests")
if not GeventConnection: def setUp(self):
raise unittest.SkipTest("Can't test gevent without monkey patching") self.connection_class = GeventConnection
#We only to patch the time module
gevent.monkey.patch_time() gevent.monkey.patch_time()
GeventConnection.initialize_reactor() GeventConnection.initialize_reactor()
def tearDown(self): def tearDown(self):
restore_saved_module("time") restore_saved_module("time")
GeventConnection._timers = None GeventConnection._timers = None
def getClass(self):
return GeventConnection

View File

@@ -116,11 +116,11 @@ class TimerConnectionTests(object):
Verify that timer timeouts are honored appropriately Verify that timer timeouts are honored appropriately
""" """
# Tests timers submitted in order at various timeouts # Tests timers submitted in order at various timeouts
submit_and_wait_for_completion(self, self.getClass(), 0, 100, 1, 100) submit_and_wait_for_completion(self, self.connection_class, 0, 100, 1, 100)
# Tests timers submitted in reverse order at various timeouts # Tests timers submitted in reverse order at various timeouts
submit_and_wait_for_completion(self, self.getClass(), 100, 0, -1, 100) submit_and_wait_for_completion(self, self.connection_class, 100, 0, -1, 100)
# Tests timers submitted in varying order at various timeouts # Tests timers submitted in varying order at various timeouts
submit_and_wait_for_completion(self, self.getClass(), 0, 100, 1, 100, True), submit_and_wait_for_completion(self, self.connection_class, 0, 100, 1, 100, True),
def test_timer_cancellation(self): def test_timer_cancellation(self):
""" """
@@ -130,11 +130,11 @@ class TimerConnectionTests(object):
# Various lists for tracking callback stage # Various lists for tracking callback stage
timeout = .1 timeout = .1
callback = TimerCallback(timeout) callback = TimerCallback(timeout)
timer = self.getClass().create_timer(timeout, callback.invoke) timer = self.connection_class.create_timer(timeout, callback.invoke)
timer.cancel() timer.cancel()
# Release context allow for timer thread to run. # Release context allow for timer thread to run.
time.sleep(.2) time.sleep(.2)
timer_manager = self.getClass()._timers timer_manager = self.connection_class._timers
# Assert that the cancellation was honored # Assert that the cancellation was honored
self.assertFalse(timer_manager._queue) self.assertFalse(timer_manager._queue)
self.assertFalse(timer_manager._new_timers) self.assertFalse(timer_manager._new_timers)

View File

@@ -8,7 +8,6 @@ deps = nose
six six
packaging packaging
cython cython
gevent
eventlet eventlet
twisted <15.5.0 twisted <15.5.0
@@ -17,12 +16,14 @@ deps = {[base]deps}
setenv = LIBEV_EMBED=0 setenv = LIBEV_EMBED=0
CARES_EMBED=0 CARES_EMBED=0
MONKEY_PATCH_LOOP=0
changedir = {envtmpdir} changedir = {envtmpdir}
commands = nosetests --verbosity=2 --no-path-adjustment {toxinidir}/tests/unit/ commands = nosetests --verbosity=2 --no-path-adjustment {toxinidir}/tests/unit/
[testenv:py27] [testenv:py27]
deps = {[base]deps} deps = {[base]deps}
gevent
setenv = LIBEV_EMBED=0 setenv = LIBEV_EMBED=0
CARES_EMBED=0 CARES_EMBED=0
@@ -35,6 +36,7 @@ commands =
[testenv:py34] [testenv:py34]
deps = {[base]deps} deps = {[base]deps}
gevent
setenv = LIBEV_EMBED=0 setenv = LIBEV_EMBED=0
CARES_EMBED=0 CARES_EMBED=0