Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test for KazooClient state listeners

  • Loading branch information...
commit 0df608ed6d46bbd3eeae6ef583a8f53666e81d0e 1 parent aa23b7b
@labisso labisso authored
Showing with 24 additions and 1 deletion.
  1. +24 −1 kazoo/test/test_client.py
View
25 kazoo/test/test_client.py
@@ -2,7 +2,7 @@
import uuid
import threading
-from kazoo.client import KazooClient
+from kazoo.client import KazooClient, KazooState
from kazoo.zkclient import EventType
from kazoo.test import get_hosts_or_skip
@@ -85,3 +85,26 @@ def test_ensure_path(self):
self.assertTrue(client.exists("/1/2/3/4"))
self.assertTrue(zk.exists(namespace + "/1/2/3/4"))
+ def test_state_listener(self):
+
+ states = []
+ condition = threading.Condition()
+
+ def listener(state):
+ with condition:
+ states.append(state)
+ condition.notify_all()
+
+ namespace = "/" + uuid.uuid4().hex
+ client = KazooClient(self.hosts, namespace=namespace)
+
+ client.add_listener(listener)
+ client.connect(5)
+
+ with condition:
+ if not states:
+ condition.wait(5)
+
+ self.assertEqual(len(states), 1)
+ self.assertEqual(states[0], KazooState.CONNECTED)
+
Please sign in to comment.
Something went wrong with that request. Please try again.