diff --git a/tests/__init__.py b/tests/__init__.py index 69ac01e..ebf9dc8 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,5 @@ import functools +import os from multiprocessing import Process from aiohttp.test_utils import unused_port @@ -12,6 +13,8 @@ from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir class BaseTestCase(AsyncTestCase): + DUMMY_EXE = os.path.join(os.path.dirname(__file__), "dummy_program.py") + def setUp(self): create_base_socket_dir() worker.stop_worker() diff --git a/tests/dummy_program.py b/tests/dummy_program.py new file mode 100755 index 0000000..ac44981 --- /dev/null +++ b/tests/dummy_program.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 + +import sys +import time +from itertools import count + +for num in count(): + time.sleep(0.5) + sys.stdout.write("Round {}\n".format(num)) + sys.stdout.flush() diff --git a/tests/test_router/test_utils.py b/tests/test_router/test_utils.py index 55b837f..7e629d2 100644 --- a/tests/test_router/test_utils.py +++ b/tests/test_router/test_utils.py @@ -13,7 +13,7 @@ class ProcessForHostnameTestCase(BaseTestCase): def test_finds_process(self): proc = subprocess.Popen( - "yes", + self.DUMMY_EXE, stdout=subprocess.PIPE, env={**os.environ, utils.HOSTNAME_ENV_VAR: "localhost"}, ) @@ -22,7 +22,7 @@ class ProcessForHostnameTestCase(BaseTestCase): def test_finds_process_with_multiple_hostnames(self): proc = subprocess.Popen( - "yes", + self.DUMMY_EXE, stdout=subprocess.PIPE, env={**os.environ, utils.HOSTNAME_ENV_VAR: "localhost,test.local"}, ) diff --git a/tests/test_utils/test_processes.py b/tests/test_utils/test_processes.py index 36090cf..2ed376f 100644 --- a/tests/test_utils/test_processes.py +++ b/tests/test_utils/test_processes.py @@ -22,7 +22,9 @@ class TerminateProcessesTestCase(BaseTestCase): def test_kills_lots_of_processes(self): created_processes = [] for _ in range(10): - created_processes.append(subprocess.Popen("yes", stdout=subprocess.PIPE)) + created_processes.append( + subprocess.Popen(self.DUMMY_EXE, stdout=subprocess.PIPE) + ) for proc in created_processes: self.assertIsNone(proc.poll()) diff --git a/tests/test_worker/test_server.py b/tests/test_worker/test_server.py index 79cee12..d7f27bf 100644 --- a/tests/test_worker/test_server.py +++ b/tests/test_worker/test_server.py @@ -5,7 +5,7 @@ from tests import BaseWorkerTestCase class WorkerServerTestCase(BaseWorkerTestCase): def test_server_creates_process(self): - response = send_to_server({"type": "process", "command": "yes"}) + response = send_to_server({"type": "process", "command": self.DUMMY_EXE}) self.assertTrue(is_process_running(response["pid"])) def test_unknown_command_type(self):