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 | 4c7414d38b032fcb84dab463a408b050dd0c7ddf (patch) | |
| tree | 5cf31931ba4bb6a93b15c67a21019355ccb38008 /qpid/python/tests/queue.py | |
| parent | a3ecd35573fff8b40f88c284d109c9f7d3462802 (diff) | |
| download | qpid-python-4c7414d38b032fcb84dab463a408b050dd0c7ddf.tar.gz | |
put queue listeners in their own thread
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@631002 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python/tests/queue.py')
| -rw-r--r-- | qpid/python/tests/queue.py | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/qpid/python/tests/queue.py b/qpid/python/tests/queue.py index d2e495d207..e12354eb43 100644 --- a/qpid/python/tests/queue.py +++ b/qpid/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) |
