diff options
author | Rafael H. Schloming <rhs@apache.org> | 2008-02-25 21:29:55 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2008-02-25 21:29:55 +0000 |
commit | 07eb942a521e951581e7a0d4558e08e4b29b6057 (patch) | |
tree | b20027151b0be8ae6833416133ddd5ed7107af3c /python/tests/queue.py | |
parent | 773cc35a38cd34095f8800259ee7a2165a817053 (diff) | |
download | qpid-python-07eb942a521e951581e7a0d4558e08e4b29b6057.tar.gz |
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
Diffstat (limited to 'python/tests/queue.py')
-rw-r--r-- | python/tests/queue.py | 41 |
1 files changed, 18 insertions, 23 deletions
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) |