Use custom program rather than yes
Yes may be too IO intensive, and may not exist on all systems
This commit is contained in:
parent
4bd7ce6f15
commit
ce29af5459
5 changed files with 19 additions and 4 deletions
|
@ -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()
|
||||
|
|
10
tests/dummy_program.py
Executable file
10
tests/dummy_program.py
Executable file
|
@ -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()
|
|
@ -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"},
|
||||
)
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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):
|
||||
|
|
Reference in a new issue