From 54a911c2f54c223338226ffbc919c726b07a73d1 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 7 Jul 2021 12:44:10 +0200 Subject: [PATCH] Revert "Kill controlled processes immediately" This reverts commit e8dde0e9892b0cf7bad6e0e1c16d5331a7c6a7ec. Actually, this breaks Limnoria's STS tests, I need to investigate this later. --- irctest/basecontrollers.py | 25 ++++++++++++++----------- irctest/client_tests/test_tls.py | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/irctest/basecontrollers.py b/irctest/basecontrollers.py index 0833b0f..6bf0494 100644 --- a/irctest/basecontrollers.py +++ b/irctest/basecontrollers.py @@ -69,7 +69,11 @@ class _BaseController: """Terminates the controlled process, waits for it to exit, and eventually kills it.""" assert self.proc - self.proc.kill() + self.proc.terminate() + try: + self.proc.wait(5) + except subprocess.TimeoutExpired: + self.proc.kill() self.proc = None def kill(self) -> None: @@ -94,6 +98,13 @@ class DirectoryBasedController(_BaseController): if self.directory: shutil.rmtree(self.directory) + def terminate(self) -> None: + """Stops the process gracefully, and does not clean its config.""" + assert self.proc + self.proc.terminate() + self.proc.wait() + self.proc = None + def open_file(self, name: str, mode: str = "a") -> IO: """Open a file in the configuration directory.""" assert self.directory @@ -171,7 +182,7 @@ class BaseServerController(_BaseController): port_open = False port: int hostname: str - services_controller: Optional[BaseServicesController] = None + services_controller: BaseServicesController extban_mute_char: Optional[str] = None """Character used for the 'mute' extban""" @@ -194,7 +205,7 @@ class BaseServerController(_BaseController): username: str, password: Optional[str] = None, ) -> None: - if self.services_controller is not None: + if self.services_controller: self.services_controller.registerUser(case, username, password) else: raise NotImplementedByController("account registration") @@ -221,16 +232,8 @@ class BaseServerController(_BaseController): continue def wait_for_services(self) -> None: - assert self.services_controller is not None self.services_controller.wait_for_services() - def kill(self) -> None: - """Calls `kill_proc` and cleans the configuration.""" - if self.services_controller is not None: - self.services_controller.kill() - self.services_controller = None - super().kill() - class BaseServicesController(_BaseController): def __init__( diff --git a/irctest/client_tests/test_tls.py b/irctest/client_tests/test_tls.py index 7e61ed3..6599795 100644 --- a/irctest/client_tests/test_tls.py +++ b/irctest/client_tests/test_tls.py @@ -186,7 +186,7 @@ class StsTestCase(cases.BaseClientTestCase, cases.OptionalityHelper): self.acceptClient() # Kill the client - self.controller.kill() + self.controller.terminate() # Run the client, still configured to connect to the insecure server self.controller.run(