Skip to content

Commit e5cb097

Browse files
committed
Closed tree cache could not be started again
1 parent f1b7edf commit e5cb097

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

kazoo/recipe/cache.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def start(self):
6262
"""
6363
if self._state == self.STATE_LATENT:
6464
self._state = self.STATE_STARTED
65+
elif self._state == self.STATE_CLOSED:
66+
raise KazooException('already closed')
6567
else:
6668
raise KazooException('already started')
6769

@@ -77,6 +79,9 @@ def close(self):
7779
A closed cache was detached from ZooKeeper's changes. And all nodes
7880
will be invalidated.
7981
82+
Once a tree cache was closed, it could not be started again. You should
83+
only close a tree cache while you want to recycle it.
84+
8085
.. note::
8186
8287
This method is not thread safe.

kazoo/tests/test_cache.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,17 @@ def test_start(self):
6262
eq_(self.cache._root._state, TreeNode.STATE_LIVE)
6363

6464
@raises(KazooException)
65-
def test_start_twice(self):
65+
def test_start_started(self):
6666
self.make_cache()
6767
self.cache.start()
6868

69+
@raises(KazooException)
70+
def test_start_closed(self):
71+
self.make_cache()
72+
self.cache.start()
73+
self.cache.close()
74+
self.cache.start()
75+
6976
def test_close(self):
7077
self.make_cache()
7178
self.wait_cache(since=TreeEvent.INITIALIZED)

0 commit comments

Comments
 (0)