def test_tcp_server_close(self): """ test that the synchronous TCP server closes correctly """ with patch.object(socket.socket, 'bind') as mock_socket: identity = ModbusDeviceIdentification(info={0x00: 'VendorName'}) server = ModbusTcpServer(context=None, identity=identity) server.threads.append(Mock(**{'running': True})) server.server_close() self.assertEqual(server.control.Identity.VendorName, 'VendorName') self.assertFalse(server.threads[0].running)
def run(self): """ Start the server. """ while not self.do_stop.is_set(): try: self.srv = ModbusTcpServer(self.context, self.framer, self.identity, (self.ip, self.port)) self.srv.allow_reuse_address = True self.srv.serve_forever() except Exception: raise print("[*] Server stopping.")
def test_tcp_server_process(self): """ test that the synchronous TCP server processes requests """ with patch('SocketServer.ThreadingTCPServer') as mock_server: server = ModbusTcpServer(None) server.process_request('request', 'client') self.assertTrue(mock_server.process_request.called)