summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqifei.wan <qifei.wan@ele.me>2017-04-24 16:58:12 +0800
committerJiangge Zhang <tonyseek@gmail.com>2017-04-24 22:00:07 +0800
commit83dca975bdb8ce0255723c0c8ac0704c0730b641 (patch)
treee1ccc8eba0d13690188cc9d6b78cb09bb59c4588
parente5cb097582e77094cd5fb8f034e803f9be0f2c0d (diff)
downloadkazoo-83dca975bdb8ce0255723c0c8ac0704c0730b641.tar.gz
Fix the infinite refresh after root node deleted
-rw-r--r--kazoo/recipe/cache.py6
-rw-r--r--kazoo/tests/test_cache.py4
2 files changed, 7 insertions, 3 deletions
diff --git a/kazoo/recipe/cache.py b/kazoo/recipe/cache.py
index bf6b92f..1e59f28 100644
--- a/kazoo/recipe/cache.py
+++ b/kazoo/recipe/cache.py
@@ -248,15 +248,14 @@ class TreeNode(object):
self._refresh_children()
def _refresh_data(self):
- self._tree._outstanding_ops += 1
self._call_client('get', self._path)
def _refresh_children(self):
# TODO max-depth checking support
- self._tree._outstanding_ops += 1
self._call_client('get_children', self._path)
def _call_client(self, method_name, path, *args):
+ self._tree._outstanding_ops += 1
callback = functools.partial(
self._tree._in_background, self._process_result,
method_name, path)
@@ -281,7 +280,8 @@ class TreeNode(object):
logger.debug('process_result: %s %s', method_name, path)
if method_name == 'exists':
assert self._parent is None, 'unexpected EXISTS on non-root'
- if result.successful():
+ # the value of result will be set with `None` if node not exists.
+ if result.get() is not None:
if self._state == self.STATE_DEAD:
self._state = self.STATE_PENDING
self.on_created()
diff --git a/kazoo/tests/test_cache.py b/kazoo/tests/test_cache.py
index 91aad05..1aa03fb 100644
--- a/kazoo/tests/test_cache.py
+++ b/kazoo/tests/test_cache.py
@@ -256,6 +256,10 @@ class KazooTreeCacheTests(KazooTestCase):
eq_(event.event_data.path, self.path)
eq_(event.event_data.stat.version, 0)
+ self.assertTrue(
+ self.cache._outstanding_ops >= 0,
+ 'unexpected outstanding ops %r' % self.cache._outstanding_ops)
+
def test_exception_handler(self):
error_value = FakeException()
error_handler = Mock()