class AsyncReqMessageClientPoolTest(TestCase): def setUp(self): super().setUp() sock_pool_size = 5 with patch( "salt.transport.zeromq.AsyncReqMessageClient.__init__", MagicMock(return_value=None), ): self.message_client_pool = AsyncReqMessageClientPool( {"sock_pool_size": sock_pool_size}, args=({}, "")) self.original_message_clients = self.message_client_pool.message_clients self.message_client_pool.message_clients = [ MagicMock() for _ in range(sock_pool_size) ] def tearDown(self): del self.original_message_clients super().tearDown() def test_send(self): for message_client_mock in self.message_client_pool.message_clients: message_client_mock.send_queue = [0, 0, 0] message_client_mock.send.return_value = [] self.assertEqual([], self.message_client_pool.send()) self.message_client_pool.message_clients[2].send_queue = [0] self.message_client_pool.message_clients[2].send.return_value = [1] self.assertEqual([1], self.message_client_pool.send())
def setUp(self): super(AsyncReqMessageClientPoolTest, self).setUp() sock_pool_size = 5 with patch('salt.transport.zeromq.AsyncReqMessageClient.__init__', MagicMock(return_value=None)): self.message_client_pool = AsyncReqMessageClientPool({'sock_pool_size': sock_pool_size}, args=({}, '')) self.original_message_clients = self.message_client_pool.message_clients self.message_client_pool.message_clients = [MagicMock() for _ in range(sock_pool_size)]
def setUp(self): super().setUp() sock_pool_size = 5 with patch( "salt.transport.zeromq.AsyncReqMessageClient.__init__", MagicMock(return_value=None), ): self.message_client_pool = AsyncReqMessageClientPool( {"sock_pool_size": sock_pool_size}, args=({}, "")) self.original_message_clients = self.message_client_pool.message_clients self.message_client_pool.message_clients = [ MagicMock() for _ in range(sock_pool_size) ]
def test_async_req_message_client_pool_send(): sock_pool_size = 5 with patch( "salt.transport.zeromq.AsyncReqMessageClient.__init__", MagicMock(return_value=None), ): message_client_pool = AsyncReqMessageClientPool( {"sock_pool_size": sock_pool_size}, args=({}, "")) message_client_pool.message_clients = [ MagicMock() for _ in range(sock_pool_size) ] for message_client_mock in message_client_pool.message_clients: message_client_mock.send_queue = [0, 0, 0] message_client_mock.send.return_value = [] with message_client_pool: assert message_client_pool.send() == [] message_client_pool.message_clients[2].send_queue = [0] message_client_pool.message_clients[2].send.return_value = [1] assert message_client_pool.send() == [1]