def setUp(self): self.server = DeviceTestServer('', 0) self.server.start(timeout=0.1) host, port = self.server._sock.getsockname() self.client = katcp.DeviceClient(host, port) self.client.start(timeout=0.1)
def setUp(self): self.client = katcp.DeviceClient('localhost', 0) self.assertFalse(self.client._received_protocol_info.isSet()) self.v4_build_state = Message.inform('build-state', 'blah-5.21a3') self.v4_version = Message.inform('version', '7.3') self.v5_version_connect_mid = Message.inform('version-connect', 'katcp-protocol', '5.0-I') self.v5_version_connect_nomid = Message.inform('version-connect', 'katcp-protocol', '5.0')
def test_request(self): client = katcp.DeviceClient(*self.server_addr) start_thread_with_cleanup(self, client, start_timeout=1) t0 = time.time() client.request(katcp.Message.request('stupidlongrequest' * 1000000), timeout=0.1) # If the send_message() call is in an EAGAIN spinning loop it will never # return, so getting here at all is a good sign :) self.assertLess(time.time() - t0, 1)
def setUp(self): self.server = DeviceTestServer('', 0) start_thread_with_cleanup(self, self.server, start_timeout=1) host, port = self.server.bind_address self.client = katcp.DeviceClient(host, port) self.client.enable_thread_safety() start_thread_with_cleanup(self, self.client, start_timeout=1) self.client.wait_connected(timeout=1)
def test_no_memory_leak_managed_ioloop(self): client = katcp.DeviceClient(self.host, self.port) wr = weakref.ref(client) self.use_on_managed_ioloop(client) # clear strong reference and check if object can be garbage collected client = None gc.collect() self.assertIsNone(wr())
def test_no_memory_leak_unmanaged_ioloop(self): client = katcp.DeviceClient(self.host, self.port) wr = weakref.ref(client) # use test's ioloop, so client does not create its own (i.e., unmanaged) yield self.use_on_unmanaged_ioloop(client) # clear strong reference and check if object can be garbage collected client = None gc.collect() self.assertIsNone(wr())
def test_no_memory_leak_invalid_server_no_reconnect(self): bad_port = 0 client = katcp.DeviceClient(self.host, bad_port, auto_reconnect=False) wr = weakref.ref(client) client.start(timeout=0.1) client.wait_connected(timeout=0.1) self.assertFalse(client.is_connected()) client.stop(timeout=0.1) client.join(timeout=0.1) # clear strong reference and check if object can be garbage collected client = None gc.collect() self.assertIsNone(wr())
def test_no_memory_leak_change_ioloop(self): client = katcp.DeviceClient(self.host, self.port) wr = weakref.ref(client) # start and stop client with managed ioloop self.use_on_managed_ioloop(client) # repeat with managed ioloop (new ioloop instance created) self.use_on_managed_ioloop(client) # change to unmanaged ioloop yield self.use_on_unmanaged_ioloop(client) # clear strong reference and check if object can be garbage collected client = None gc.collect() self.assertIsNone(wr())
def test_no_memory_leak_stopped_server(self): client = katcp.DeviceClient(self.host, self.port) wr = weakref.ref(client) client.auto_reconnect_delay = 0.01 client.start(timeout=0.1) client.wait_protocol(timeout=0.1) self.assertTrue(client.protocol_flags) # stop server before client self.server.stop() client.wait_disconnected(timeout=0.1) self.assertFalse(client.is_connected()) client.stop(timeout=0.1) client.join(timeout=0.1) # clear strong reference and check if object can be garbage collected client = None gc.collect() self.assertIsNone(wr())
def test_no_memory_leak_stop_current_ioloop(self): # The DeviceClient may use the current ioloop during initialisation. # Similarly, the DeviceTestServer created in setUp() may have references to # the current ioloop. We make a new instance to replace the current # ioloop, which we can stop without affecting the server. This test aims # to verify that the client is not dependent on the ioloop that was # current at the time the client was initialised. This is only for # the "managed" ioloop case. ioloop = tornado.ioloop.IOLoop() tornado.ioloop.IOLoop.make_current(ioloop) client = katcp.DeviceClient(self.host, self.port) wr = weakref.ref(client) # close ioloop that was current when client created ioloop.close() self.use_on_managed_ioloop(client) # clear strong reference and check if object can be garbage collected client = None gc.collect() self.assertIsNone(wr())