Kill controlled processes immediately

Also ensures services are always stopped (so far, they were not if
they ignored SIGTERM but the ircd honors SIGTERM)
This commit is contained in:
2021-07-07 12:13:40 +02:00
parent 314439787a
commit e8dde0e989
2 changed files with 12 additions and 15 deletions

View File

@ -69,10 +69,6 @@ class _BaseController:
"""Terminates the controlled process, waits for it to exit, and """Terminates the controlled process, waits for it to exit, and
eventually kills it.""" eventually kills it."""
assert self.proc assert self.proc
self.proc.terminate()
try:
self.proc.wait(5)
except subprocess.TimeoutExpired:
self.proc.kill() self.proc.kill()
self.proc = None self.proc = None
@ -98,13 +94,6 @@ class DirectoryBasedController(_BaseController):
if self.directory: if self.directory:
shutil.rmtree(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: def open_file(self, name: str, mode: str = "a") -> IO:
"""Open a file in the configuration directory.""" """Open a file in the configuration directory."""
assert self.directory assert self.directory
@ -182,7 +171,7 @@ class BaseServerController(_BaseController):
port_open = False port_open = False
port: int port: int
hostname: str hostname: str
services_controller: BaseServicesController services_controller: Optional[BaseServicesController] = None
extban_mute_char: Optional[str] = None extban_mute_char: Optional[str] = None
"""Character used for the 'mute' extban""" """Character used for the 'mute' extban"""
@ -205,7 +194,7 @@ class BaseServerController(_BaseController):
username: str, username: str,
password: Optional[str] = None, password: Optional[str] = None,
) -> None: ) -> None:
if self.services_controller: if self.services_controller is not None:
self.services_controller.registerUser(case, username, password) self.services_controller.registerUser(case, username, password)
else: else:
raise NotImplementedByController("account registration") raise NotImplementedByController("account registration")
@ -232,8 +221,16 @@ class BaseServerController(_BaseController):
continue continue
def wait_for_services(self) -> None: def wait_for_services(self) -> None:
assert self.services_controller is not None
self.services_controller.wait_for_services() 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): class BaseServicesController(_BaseController):
def __init__( def __init__(

View File

@ -186,7 +186,7 @@ class StsTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
self.acceptClient() self.acceptClient()
# Kill the client # Kill the client
self.controller.terminate() self.controller.kill()
# Run the client, still configured to connect to the insecure server # Run the client, still configured to connect to the insecure server
self.controller.run( self.controller.run(