This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
catfish/tests/test_worker/test_server.py

29 lines
1.2 KiB
Python
Raw Normal View History

2018-12-13 11:25:09 +00:00
from catfish.utils.processes import is_process_running
2018-12-13 16:52:37 +00:00
from catfish.utils.sockets import stdout_socket_for_pid
2018-12-18 20:41:23 +00:00
from catfish.worker.server import PayloadType, read_from_stdout_socket, send_to_server
2018-12-13 11:36:22 +00:00
from tests import BaseWorkerTestCase
2018-12-13 11:25:09 +00:00
class WorkerServerTestCase(BaseWorkerTestCase):
def test_server_creates_process(self):
2018-12-18 20:41:23 +00:00
response = send_to_server(PayloadType.PROCESS, {"command": str(self.DUMMY_EXE)})
2018-12-13 11:36:22 +00:00
self.assertTrue(is_process_running(response["pid"]))
def test_ping(self):
2018-12-18 20:41:23 +00:00
response = send_to_server(PayloadType.PING, {})
2018-12-13 11:36:22 +00:00
self.assertEqual(response, {"ping": "pong"})
2018-12-13 16:52:37 +00:00
class ProcessLogsTestCase(BaseWorkerTestCase):
def test_creates_socket(self):
2018-12-18 20:41:23 +00:00
response = send_to_server(PayloadType.PROCESS, {"command": str(self.DUMMY_EXE)})
2018-12-13 16:52:37 +00:00
stdout_socket = stdout_socket_for_pid(response["pid"])
2018-12-18 15:49:20 +00:00
self.assertTrue(stdout_socket.exists())
2018-12-13 16:52:37 +00:00
def test_gets_logs(self):
2018-12-18 20:41:23 +00:00
response = send_to_server(PayloadType.PROCESS, {"command": str(self.DUMMY_EXE)})
2018-12-13 16:52:37 +00:00
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))