Crash when a controlled process stopped instead of waiting forever.

This commit is contained in:
2021-02-24 12:58:39 +01:00
committed by Valentin Lorentz
parent 932e9ade5a
commit 8ea7197f76
2 changed files with 24 additions and 2 deletions

View File

@ -8,6 +8,12 @@ import time
from .runner import NotImplementedByController
class ProcessStopped(Exception):
"""Raised when the controlled process stopped unexpectedly"""
pass
class _BaseController:
"""Base class for software controllers.
@ -17,6 +23,12 @@ class _BaseController:
def __init__(self, test_config):
self.test_config = test_config
self.proc = None
def check_is_alive(self):
self.proc.poll()
if self.proc.returncode is not None:
raise ProcessStopped()
class DirectoryBasedController(_BaseController):
@ -26,7 +38,6 @@ class DirectoryBasedController(_BaseController):
def __init__(self, test_config):
super().__init__(test_config)
self.directory = None
self.proc = None
def kill_proc(self):
"""Terminates the controlled process, waits for it to exit, and
@ -132,6 +143,7 @@ class BaseServerController(_BaseController):
def wait_for_port(self):
while not self.port_open:
self.check_is_alive()
time.sleep(self._port_wait_interval)
try:
c = socket.create_connection(("localhost", self.port), timeout=1.0)

View File

@ -165,10 +165,20 @@ class BaseClientTestCase(_IrcTestCase):
self.server.bind(("", 0)) # Bind any free port
self.server.listen(1)
# Used to check if the client is alive from time to time
self.server.settimeout(1)
def acceptClient(self, tls_cert=None, tls_key=None, server=None):
"""Make the server accept a client connection. Blocking."""
server = server or self.server
# Wait for the client to connect
while True:
try:
(self.conn, addr) = server.accept()
except socket.timeout:
self.controller.check_is_alive()
else:
break
if tls_cert is None and tls_key is None:
pass
else: