X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=test%2Fcommon.py;h=38c59d588e72c87e1683cb2c4a3dc9d3853ae392;hb=40cb094a4abc7a375b796d318fab7c05a5e9bd1a;hp=5f6c753fd0ae6f5863b29d41f1e76d489b8e865e;hpb=14683d91ed3172b416b1c3e5e59edd6528f30a69;p=loctrkd.git diff --git a/test/common.py b/test/common.py index 5f6c753..38c59d5 100644 --- a/test/common.py +++ b/test/common.py @@ -23,17 +23,33 @@ from unittest import TestCase class TestWithServers(TestCase): def setUp(self, *args: str) -> None: - with closing(socket(AF_INET6, SOCK_DGRAM)) as sock: - sock.bind(("", 0)) - sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) - freeport = sock.getsockname()[1] + with closing(socket(AF_INET6, SOCK_DGRAM)) as sock1, closing( + socket(AF_INET6, SOCK_DGRAM) + ) as sock2: + freeports = [] + for sock in sock1, sock2: + sock.bind(("", 0)) + sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) + freeports.append(sock.getsockname()[1]) _, self.tmpfilebase = mkstemp() self.conf = ConfigParser() self.conf["collector"] = { - "port": str(freeport), + "port": str(freeports[0]), "publishurl": "ipc://" + self.tmpfilebase + ".pub", "listenurl": "ipc://" + self.tmpfilebase + ".pul", } + self.conf["storage"] = { + "dbfn": self.tmpfilebase + ".storage.sqlite", + } + self.conf["opencellid"] = { + "dbfn": self.tmpfilebase + ".opencellid.sqlite", + } + self.conf["lookaside"] = { + "backend": "opencellid", + } + self.conf["wsgateway"] = { + "port": str(freeports[1]), + } self.children = [] for srvname in args: if srvname == "collector": @@ -47,7 +63,6 @@ class TestWithServers(TestCase): sleep(1) def tearDown(self) -> None: - sleep(1) for srvname, p in self.children: if p.pid is not None: kill(p.pid, SIGINT) @@ -57,8 +72,17 @@ class TestWithServers(TestCase): 0, srvname + " terminated with non-zero return code", ) - for sfx in (".pub", ".pul"): - unlink(self.tmpfilebase + sfx) + for sfx in ( + "", + ".pub", + ".pul", + ".storage.sqlite", + ".opencellid.sqlite", + ): + try: + unlink(self.tmpfilebase + sfx) + except OSError: + pass def send_and_drain(sock: SocketType, buf: Optional[bytes]) -> None: