From 5942105e2e04fd6397a4332335f08f67f136ac88 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Mon, 20 Jun 2016 18:08:24 +0100 Subject: [PATCH] Don't cache and re-use the websocket The socket is bound to the queue name and this this removes the ability to work with multiple queues and if the websocket it closed it can't be easily recreated. Change-Id: I6d05b9536111a77a54b818dcf1a9d030ad464e7f --- tripleoclient/plugin.py | 6 +----- tripleoclient/tests/fakes.py | 5 +---- tripleoclient/tests/test_plugin.py | 10 +++++----- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/tripleoclient/plugin.py b/tripleoclient/plugin.py index 156ad4a1d..db1b3631c 100644 --- a/tripleoclient/plugin.py +++ b/tripleoclient/plugin.py @@ -148,11 +148,7 @@ class ClientWrapper(object): def __init__(self, instance): self._instance = instance - self._messaging_websocket = None def messaging_websocket(self, queue_name='tripleo'): """Returns a websocket for the messaging service""" - if self._messaging_websocket is not None: - return self._messaging_websocket - self._messaging_websocket = WebsocketClient(self._instance, queue_name) - return self._messaging_websocket + return WebsocketClient(self._instance, queue_name) diff --git a/tripleoclient/tests/fakes.py b/tripleoclient/tests/fakes.py index de282a6af..9282cf4e8 100644 --- a/tripleoclient/tests/fakes.py +++ b/tripleoclient/tests/fakes.py @@ -40,8 +40,5 @@ class FakeClientManager(object): class FakeClientWrapper(object): - def __init__(self): - self._messaging_websocket = mock.MagicMock() - def messaging_websocket(self, queue_name='tripleo'): - return self._messaging_websocket + return mock.MagicMock() diff --git a/tripleoclient/tests/test_plugin.py b/tripleoclient/tests/test_plugin.py index 851b172a2..4702560e1 100644 --- a/tripleoclient/tests/test_plugin.py +++ b/tripleoclient/tests/test_plugin.py @@ -38,15 +38,15 @@ class TestPlugin(base.TestCase): client = plugin.make_client(clientmgr) websocket = client.messaging_websocket() - # The second access should return the same client: - self.assertIs(client.messaging_websocket(), websocket) + # The second access should not return the same client: + self.assertIsNot(client.messaging_websocket(), websocket) plugin.make_client(clientmgr) # And the functions should only be called when the client is created: - self.assertEqual(clientmgr.auth.get_token.call_count, 1) - self.assertEqual(clientmgr.get_endpoint_for_service_type.call_count, 1) - ws_create_connection.assert_called_once_with("ws://0.0.0.0") + self.assertEqual(clientmgr.auth.get_token.call_count, 2) + self.assertEqual(clientmgr.get_endpoint_for_service_type.call_count, 2) + ws_create_connection.assert_called_with("ws://0.0.0.0") @mock.patch.object(plugin.WebsocketClient, "recv") @mock.patch("websocket.create_connection")