Kill all dummy processes after launch

Just in case
This commit is contained in:
Jake Howard 2018-12-15 16:23:06 +00:00
parent f1b4017789
commit 3bc8de98e6
Signed by: jake
GPG key ID: 57AFB45680EDD477

View file

@ -2,6 +2,7 @@ import functools
import os
import shutil
import subprocess
from unittest import TestCase
from aiohttp.test_utils import AioHTTPTestCase, unused_port
from aiounittest import AsyncTestCase
@ -9,11 +10,15 @@ from click.testing import CliRunner
from catfish.__main__ import cli
from catfish.router import get_server
from catfish.utils.processes import terminate_subprocesses
from catfish.utils.processes import (
get_root_process,
terminate_processes,
terminate_subprocesses,
)
from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir
class BaseTestCase(AsyncTestCase):
class BaseTestCase(TestCase):
DUMMY_EXE = os.path.join(os.path.dirname(__file__), "dummy_program.py")
def setUp(self):
@ -22,8 +27,16 @@ class BaseTestCase(AsyncTestCase):
self.cli = cli
self.run_cli = functools.partial(self.cli_runner.invoke, self.cli)
def terminate_dummy_processes(self):
dummy_processes = []
for process in get_root_process().children(recursive=True):
if self.DUMMY_EXE in " ".join(process.cmdline()):
dummy_processes.append(process)
terminate_processes(dummy_processes)
def tearDown(self):
terminate_subprocesses()
self.terminate_dummy_processes()
delete_base_socket_dir()