diff --git a/oslo/messaging/_drivers/impl_fake.py b/oslo/messaging/_drivers/impl_fake.py index 7b9ab6d57..ffce9677a 100644 --- a/oslo/messaging/_drivers/impl_fake.py +++ b/oslo/messaging/_drivers/impl_fake.py @@ -32,9 +32,8 @@ class FakeIncomingMessage(base.IncomingMessage): self._reply_q = reply_q def reply(self, reply=None, failure=None, log_failure=True): - # FIXME: handle failure if self._reply_q: - self._reply_q.put(reply) + self._reply_q.put((reply, failure)) class FakeListener(base.Listener): @@ -129,7 +128,11 @@ class FakeDriver(base.BaseDriver): if wait_for_reply: try: - return reply_q.get(timeout=timeout) + reply, failure = reply_q.get(timeout=timeout) + if failure: + raise failure + else: + return reply except Queue.Empty: raise messaging.MessagingTimeout( 'No reply on topic %s' % target.topic) diff --git a/tests/test_rpc_server.py b/tests/test_rpc_server.py index 71e3c5644..4d28a7995 100644 --- a/tests/test_rpc_server.py +++ b/tests/test_rpc_server.py @@ -258,6 +258,35 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin): self._stop_server(client, server_thread) + def test_failure(self): + transport = messaging.get_transport(self.conf, url='fake:') + + class TestEndpoint(object): + def ping(self, ctxt, arg): + raise ValueError + + server_thread = self._setup_server(transport, TestEndpoint()) + client = self._setup_client(transport) + + self.assertRaises(ValueError, client.call, {}, 'ping', arg='foo') + + self._stop_server(client, server_thread) + + def test_expected_failure(self): + transport = messaging.get_transport(self.conf, url='fake:') + + class TestEndpoint(object): + @messaging.expected_exceptions(ValueError) + def ping(self, ctxt, arg): + raise ValueError + + server_thread = self._setup_server(transport, TestEndpoint()) + client = self._setup_client(transport) + + self.assertRaises(ValueError, client.call, {}, 'ping', arg='foo') + + self._stop_server(client, server_thread) + class TestMultipleServers(test_utils.BaseTestCase, ServerSetupMixin):