class ClientsMapTest(TestCase): def setUp(self): self.talker = Talker(client_cls=TestClient) self.map = self.talker.clients self.talker.start() self.sock = socket.socket() def tearDown(self): self.sock.close() self.talker.stop() def test_socket_client_init(self): self.assertEqual(self.map.by_fileno, {}) self.sock.connect(('localhost', self.talker.port)) wait_for(lambda: self.map.by_fileno) self.assertEqual(len(self.map.by_fileno), 1) client = self.map.by_fileno.values()[0] self.assertIsInstance(client, TestClient) self.assertEqual(client, self.map.by_cid[client.id]) self.sock.close() wait_for(lambda: not self.map.by_fileno) self.assertEqual(self.map.by_fileno, {}) def test_queue(self): client = TestClient(FakeSocket(), None, self.talker) self.map[0] = client self.map.queue([client.id], 'hello') self.assertEqual(client.queue, ['hello'])
class Zt_Talker_Base(TestCase): def setUp(self): port = random.choice(range(5000, 6500)) Talker.epoll_timeout = 0.1 self.talker = Talker(port=port, client_cls=TestClient) self.talker.start() self.sender = Sender('', port) def tearDown(self): self.talker.stop() time.sleep(Talker.epoll_timeout)
class Zt_Base(TestCase): def wait(self): time.sleep(self.talker.epoll_timeout * 2) def create_sender(self): return Sender('', self.talker.port) def setUp(self): TestClient.disconnected = [] self.talker = Talker(port=64533, client_cls=TestClient) Talker.port = 64536 self.talker.start() self.wait_equal(self.talker.is_alive, True) self.sender = self.create_sender() self.wait() def tearDown(self): self.talker.stop() self.wait()