def test_start(self): port = choose_port() with master_context(port=port): time.sleep(QUANTUM_SECONDS) with mock_client(port) as client: client.send(b"START %s p1 p2 p3 p4 p5 p6\n" % PLAYER_HOSTNAME) text = client.readline()
def test_exit(self): port = choose_port() with player_context(port) as proc: time.sleep(QUANTUM_SECONDS) with mock_client(port, socket.SOCK_DGRAM) as client: client.send(b"QUIT\n") ret = proc.wait(5) self.assertEqual(ret, 0)
def test_start_wrong_host(self): port = choose_port() with master_context(port=port): time.sleep(QUANTUM_SECONDS) with mock_client(port) as client: client.send(b"START definitely_nonexistent 1 2 3 4 5 6\n") line = client.recv(100) self.assertIn(b"ERROR", line)
def test_wrong_command(self): port = choose_port() with master_context((str(port),), stderr=None, stdout=None): time.sleep(QUANTUM_SECONDS) with mock_client(port) as client: client.send(b"WRONG_COMMAND\n") line = client.recv(100) self.assertIn(b"ERROR", line) client.send(b"WRONG_COMMAND\n") line = client.recv(100) self.assertIn(b"ERROR", line)
def test_start(self): port = choose_port() with master_context(port=port): time.sleep(QUANTUM_SECONDS) with mock_client(port) as client: client.send(b"START %s p1 p2 p3 p4 p5 p6\n" % PLAYER_HOSTNAME) text = client.recv(100) ok, num_str = text.strip().split() self.assertEqual(ok, b"OK") client_num = int(num_str) time.sleep(QUANTUM_SECONDS) # TODO: assert that ssh was executed with correct parameters # TODO: assert that the client is still running client.send(b"QUIT %d\n" % client_num) time.sleep(QUANTUM_SECONDS) ok = client.recv(100) self.assertEqual(ok, b"OK %d\n" % client_num)
def master_and_mock_client(): port = choose_port() with master_context(port=port): time.sleep(QUANTUM_SECONDS) with mock_client(port) as client: yield client