diff --git a/tests/system_test.py b/tests/system_test.py index c491feb6a..13235b64d 100755 --- a/tests/system_test.py +++ b/tests/system_test.py @@ -39,6 +39,7 @@ import re import shlex import shutil +import signal import socket import subprocess import sys @@ -366,12 +367,16 @@ def error(msg): try: self.wait(TIMEOUT) except TimeoutExpired: - self.kill() - error("did not terminate properly, required kill()") + self.send_signal(signal.SIGABRT) # so that we may get core dump + error("did not terminate properly, required SIGABORT") # at this point the process has terminated, either of its own accord or # due to the above terminate call. + # prevent leak of stdin fd + if self.stdin: + self.stdin.close() + if state is None and self.expect != Process.RUNNING: error("process was unexpectedly still running") @@ -563,6 +568,13 @@ def __init__(self, name=None, config=Config(), pyinclude=None, wait=True, if wait: self.wait_ready() + def __enter__(self): + """Allows using the class in the `with` contextmanager""" + return self + + def __exit__(self, *_): + self.teardown() + @property def management(self): """Return a management agent proxy for this router""" diff --git a/tests/system_tests_one_router.py b/tests/system_tests_one_router.py index 7cb42362d..bf13a5273 100644 --- a/tests/system_tests_one_router.py +++ b/tests/system_tests_one_router.py @@ -411,8 +411,8 @@ def test_01_listen_error(self): config = Qdrouterd.Config([ ('router', {'mode': 'standalone', 'id': 'bad'}), ('listener', {'port': OneRouterTest.listen_port})]) - r = Qdrouterd(name="expect_fail", config=config, wait=False) - self.assertEqual(1, r.wait()) + with Qdrouterd(name="expect_fail", config=config, wait=False, expect=Process.EXIT_FAIL) as r: + self.assertEqual(1, r.wait()) def test_02_pre_settled(self): addr = self.address + '/closest/' + str(OneRouterTest.closest_count)