Fix assumptions in test_server_wait_method
test_server_wait_method was calling server.wait without having previously called server.start and server.stop. This happened to work because it also injected server._executor_obj. This is problematic, though, as it assumes internal details of the server and does not represent the calling contract of server.wait, which is that it must follow server.stop (which must itself also follow server.start). This change makes the necessary changes to call server.wait in the correct sequence. Change-Id: I205683ac6e0f2d64606bb06d08d3d1419f7645f4
This commit is contained in:
parent
aec50602d5
commit
9d74ee40c6
@ -117,14 +117,23 @@ class TestRPCServer(test_utils.BaseTestCase, ServerSetupMixin):
|
||||
endpoints = [object()]
|
||||
serializer = object()
|
||||
|
||||
class MagicMockIgnoreArgs(mock.MagicMock):
|
||||
'''A MagicMock which can never misinterpret the arguments passed to
|
||||
it during construction.'''
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MagicMockIgnoreArgs, self).__init__()
|
||||
|
||||
server = oslo_messaging.get_rpc_server(transport, target, endpoints,
|
||||
serializer=serializer)
|
||||
# Mocking executor
|
||||
server._executor_obj = mock.Mock()
|
||||
server._executor_cls = MagicMockIgnoreArgs
|
||||
# Here assigning executor's listener object to listener variable
|
||||
# before calling wait method, because in wait method we are
|
||||
# setting executor to None.
|
||||
server.start()
|
||||
listener = server._executor_obj.listener
|
||||
server.stop()
|
||||
# call server wait method
|
||||
server.wait()
|
||||
self.assertIsNone(server._executor_obj)
|
||||
|
Loading…
x
Reference in New Issue
Block a user