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:
parent
032639e677
commit
71588adbb5
0
oslo/messaging/_cmd/zmq_receiver.py
Executable file → Normal file
0
oslo/messaging/_cmd/zmq_receiver.py
Executable file → Normal file
@ -116,7 +116,10 @@ class AMQPListener(base.Listener):
|
||||
timeout = deadline - time.time()
|
||||
if timeout < 0:
|
||||
return None
|
||||
try:
|
||||
self.conn.consume(limit=1, timeout=timeout)
|
||||
except rpc_common.Timeout:
|
||||
return None
|
||||
else:
|
||||
self.conn.consume(limit=1)
|
||||
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user