From 07eb942a521e951581e7a0d4558e08e4b29b6057 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Mon, 25 Feb 2008 21:29:55 +0000 Subject: put queue listeners in their own thread git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@631002 13f79535-47bb-0310-9956-ffa450edef68 --- python/tests/queue.py | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'python/tests/queue.py') diff --git a/python/tests/queue.py b/python/tests/queue.py index d2e495d207..e12354eb43 100644 --- a/python/tests/queue.py +++ b/python/tests/queue.py @@ -30,37 +30,32 @@ class QueueTest (TestCase): # all the queue functionality. def test_listen(self): - LISTEN = object() - GET = object() - EMPTY = object() + values = [] + heard = threading.Event() + def listener(x): + values.append(x) + heard.set() q = Queue(0) - values = [] - q.listen(lambda x: values.append((LISTEN, x))) + q.listen(listener) + heard.clear() q.put(1) - assert values[-1] == (LISTEN, 1) + heard.wait() + assert values[-1] == 1 + heard.clear() q.put(2) - assert values[-1] == (LISTEN, 2) - - class Getter(threading.Thread): + heard.wait() + assert values[-1] == 2 - def run(self): - try: - values.append((GET, q.get(timeout=10))) - except Empty: - values.append(EMPTY) - - g = Getter() - g.start() - # let the other thread reach the get - time.sleep(2) + q.listen(None) q.put(3) - g.join() - - assert values[-1] == (GET, 3) + assert q.get(3) == 3 + q.listen(listener) + heard.clear() q.put(4) - assert values[-1] == (LISTEN, 4) + heard.wait() + assert values[-1] == 4 def test_close(self): q = Queue(0) -- cgit v1.2.1