From e309a84d548213caf4382eda215dabf969332de4 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Thu, 8 Dec 2022 12:43:36 +0100 Subject: [PATCH] Fix test when servers crash; less logging --- loctrkd/collector.py | 4 ++-- test/common.py | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/loctrkd/collector.py b/loctrkd/collector.py index 5c1c34e..216134e 100644 --- a/loctrkd/collector.py +++ b/loctrkd/collector.py @@ -44,7 +44,7 @@ class Client: else: rest = b"" if rest: - log.warning( + log.info( "%d bytes in buffer on close: %s", len(rest), rest[:64].hex() ) @@ -85,7 +85,7 @@ class Client: if isinstance(elem, bytes): msgs.append((when, self.addr, elem)) else: - log.warning( + log.info( "%s from fd %d (IMEI %s)", elem, self.sock.fileno(), diff --git a/test/common.py b/test/common.py index a31ff09..17446a5 100644 --- a/test/common.py +++ b/test/common.py @@ -4,7 +4,7 @@ from configparser import ConfigParser, SectionProxy from contextlib import closing, ExitStack from http.server import HTTPServer, SimpleHTTPRequestHandler from importlib import import_module -from logging import DEBUG, StreamHandler +from logging import DEBUG, StreamHandler, WARNING from multiprocessing import Process from os import kill, unlink from signal import SIGINT @@ -79,6 +79,8 @@ class TestWithServers(TestCase): if verbose: cls.log.addHandler(StreamHandler(stderr)) cls.log.setLevel(DEBUG) + else: + cls.log.setLevel(WARNING) p = Process(target=cls.runserver, args=(self.conf,), kwargs=kwargs) p.start() self.children.append((srvname, p)) @@ -96,17 +98,17 @@ class TestWithServers(TestCase): p.start() self.children.append(("httpd", p)) sleep(1) + for srvname, p in self.children: + self.assertTrue( + p.is_alive(), + f"{srvname} did not start, exit code {p.exitcode}", + ) def tearDown(self) -> None: for srvname, p in self.children: if p.pid is not None: kill(p.pid, SIGINT) p.join() - self.assertEqual( - p.exitcode, - 0, - f"{srvname} terminated with return code {p.exitcode}", - ) for sfx in ( "", ".pub", @@ -119,6 +121,12 @@ class TestWithServers(TestCase): unlink(self.tmpfilebase + sfx) except OSError: pass + for srvname, p in self.children: + self.assertEqual( + p.exitcode, + 0, + f"{srvname} terminated with exit code {p.exitcode}", + ) class Fuzz(TestWithServers): -- 2.43.0