32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
from catfish.utils.processes import is_process_running
|
|
from catfish.utils.sockets import stdout_socket_for_pid
|
|
from catfish.worker.server import read_from_stdout_socket, send_to_server
|
|
from tests import BaseWorkerTestCase
|
|
|
|
|
|
class WorkerServerTestCase(BaseWorkerTestCase):
|
|
def test_server_creates_process(self):
|
|
response = send_to_server({"type": "process", "command": str(self.DUMMY_EXE)})
|
|
self.assertTrue(is_process_running(response["pid"]))
|
|
|
|
def test_unknown_command_type(self):
|
|
response = send_to_server({"type": "nothing"})
|
|
self.assertEqual(response, {"error": "Invalid command"})
|
|
|
|
def test_ping(self):
|
|
response = send_to_server({"type": "ping"})
|
|
self.assertEqual(response, {"ping": "pong"})
|
|
|
|
|
|
class ProcessLogsTestCase(BaseWorkerTestCase):
|
|
def test_creates_socket(self):
|
|
response = send_to_server({"type": "process", "command": str(self.DUMMY_EXE)})
|
|
stdout_socket = stdout_socket_for_pid(response["pid"])
|
|
self.assertTrue(stdout_socket.exists())
|
|
|
|
def test_gets_logs(self):
|
|
response = send_to_server({"type": "process", "command": str(self.DUMMY_EXE)})
|
|
stdout_socket = stdout_socket_for_pid(response["pid"])
|
|
stdout_iter = read_from_stdout_socket(stdout_socket)
|
|
for i in range(3):
|
|
self.assertEqual(next(stdout_iter), "Round {}".format(i))
|