Fix AMQPListener for polling with timeout

On timeout, poll() should return None, not raise an exception (Timeout).

Add also an unit test.

Change-Id: I1ed5ae2f093841111f0b691dddb879c16d218b73
This commit is contained in:
Victor Stinner 2014-07-07 12:25:12 +00:00
parent 032639e677
commit 71588adbb5
3 changed files with 21 additions and 1 deletions

0
oslo/messaging/_cmd/zmq_receiver.py Executable file → Normal file
View File

View File

@ -116,7 +116,10 @@ class AMQPListener(base.Listener):
timeout = deadline - time.time()
if timeout < 0:
return None
self.conn.consume(limit=1, timeout=timeout)
try:
self.conn.consume(limit=1, timeout=timeout)
except rpc_common.Timeout:
return None
else:
self.conn.consume(limit=1)

View File

@ -265,6 +265,23 @@ class TestSendReceive(test_utils.BaseTestCase):
TestSendReceive.generate_scenarios()
class TestPollAsync(test_utils.BaseTestCase):
def setUp(self):
super(TestPollAsync, self).setUp()
self.messaging_conf.transport_driver = 'rabbit'
self.messaging_conf.in_memory = True
def test_poll_timeout(self):
transport = messaging.get_transport(self.conf)
self.addCleanup(transport.cleanup)
driver = transport._driver
target = messaging.Target(topic='testtopic')
listener = driver.listen(target)
received = listener.poll(timeout=0.050)
self.assertIsNone(received)
class TestRacyWaitForReply(test_utils.BaseTestCase):
def setUp(self):