Skip to content

Commit

Permalink
refactor: Test various handler on TreeCache
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyseek committed Oct 2, 2018
1 parent 48999f5 commit 4115dd4
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions kazoo/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,39 @@
from nose.tools import eq_, ok_, assert_not_equal, raises
from objgraph import count as count_refs_by_type

from kazoo.testing import KazooTestCase
from kazoo.testing import KazooTestHarness
from kazoo.exceptions import KazooException
from kazoo.recipe.cache import TreeCache, TreeNode, TreeEvent


class KazooTreeCacheTests(KazooTestCase):
class KazooAdaptiveHandlerTestCase(KazooTestHarness):
def setUp(self):
self.handler = self.choose_an_installed_handler()
self.setup_zookeeper(handler=self.handler)

def tearDown(self):
self.teardown_zookeeper()

def choose_an_installed_handler(self):
try:
from kazoo.handlers.gevent import SequentialGeventHandler
except ImportError:
pass
else:
return SequentialGeventHandler()

try:
from kazoo.handlers.eventlet import SequentialEventletHandler
except ImportError:
pass
else:
return SequentialEventletHandler()

from kazoo.handlers.threading import SequentialThreadingHandler
return SequentialThreadingHandler()


class KazooTreeCacheTests(KazooAdaptiveHandlerTestCase):
def setUp(self):
super(KazooTreeCacheTests, self).setUp()
self._event_queue = self.client.handler.queue_impl()
Expand All @@ -20,7 +46,6 @@ def setUp(self):
self.cache = None

def tearDown(self):
super(KazooTreeCacheTests, self).tearDown()
if not self._error_queue.empty():
try:
raise self._error_queue.get()
Expand All @@ -29,6 +54,8 @@ def tearDown(self):
if self.cache is not None:
self.cache.close()
self.cache = None
self.handler = None
super(KazooTreeCacheTests, self).tearDown()

def make_cache(self):
if self.cache is None:
Expand Down Expand Up @@ -57,7 +84,11 @@ def spy_client(self, method_name):
return patch.object(self.client, method_name, wraps=method)

def _gc_wait(self):
while not self.client.handler.completion_queue.empty():
if self.handler.name == 'sequential_threading_handler':
while not self.client.handler.completion_queue.empty():
self.client.handler.sleep_func(0.1)
else:
# Let hub of gevent/eventlet be in short-time loop
self.client.handler.sleep_func(0.1)
for gen in range(3):
gc.collect(gen)
Expand Down

0 comments on commit 4115dd4

Please sign in to comment.