Merge "Don't cache and re-use the websocket"

This commit is contained in:
Jenkins 2016-07-04 07:57:52 +00:00 committed by Gerrit Code Review
commit 7910d07dfc
3 changed files with 7 additions and 14 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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")