X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=test%2Fcommon.py;h=a31ff094d9d806ebfa5b1572d49587a2a20c7bd8;hb=2a5d40ae0d3eebe40e6b53ee0776e10b228179f2;hp=761ea6721a267c832af4d3dfca910f6cbbb2dbb9;hpb=5bd4b1bad2506f2f5f71161ac9e8a9b141e0fef4;p=loctrkd.git diff --git a/test/common.py b/test/common.py index 761ea67..a31ff09 100644 --- a/test/common.py +++ b/test/common.py @@ -9,20 +9,26 @@ from multiprocessing import Process from os import kill, unlink from signal import SIGINT from socket import ( + AF_INET, AF_INET6, + getaddrinfo, MSG_DONTWAIT, SOCK_DGRAM, + SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR, socket, SocketType, ) from sys import exit, stderr +from random import Random from tempfile import mkstemp from time import sleep -from typing import Optional +from typing import Any, Optional from unittest import TestCase +from loctrkd.common import init_protocols + NUMPORTS = 3 @@ -39,25 +45,30 @@ class TestWithServers(TestCase): freeports.append(sk.getsockname()[1]) _, self.tmpfilebase = mkstemp() self.conf = ConfigParser() + self.conf["common"] = { + "protocols": "zx303proto,beesure", + } self.conf["collector"] = { "port": str(freeports[0]), "publishurl": "ipc://" + self.tmpfilebase + ".pub", "listenurl": "ipc://" + self.tmpfilebase + ".pul", - "protocols": "zx303proto", } self.conf["storage"] = { "dbfn": self.tmpfilebase + ".storage.sqlite", + "events": "yes", } self.conf["opencellid"] = { "dbfn": self.tmpfilebase + ".opencellid.sqlite", "downloadurl": f"http://localhost:{freeports[2]}/test/262.csv.gz", } self.conf["rectifier"] = { - "backend": "opencellid", + "lookaside": "opencellid", + "publishurl": "ipc://" + self.tmpfilebase + ".rect.pub", } self.conf["wsgateway"] = { "port": str(freeports[1]), } + init_protocols(self.conf) self.children = [] for srvname in args: if srvname == "collector": @@ -99,6 +110,7 @@ class TestWithServers(TestCase): for sfx in ( "", ".pub", + ".rect.pub", ".pul", ".storage.sqlite", ".opencellid.sqlite", @@ -109,6 +121,28 @@ class TestWithServers(TestCase): pass +class Fuzz(TestWithServers): + def setUp(self, *args: str, **kwargs: Any) -> None: + super().setUp("collector") + self.rnd = Random() + for fam, typ, pro, cnm, skadr in getaddrinfo( + "127.0.0.1", + self.conf.getint("collector", "port"), + family=AF_INET, + type=SOCK_STREAM, + ): + break # Just take the first element + self.sock = socket(AF_INET, SOCK_STREAM) + self.sock.connect(skadr) + + def tearDown(self) -> None: + sleep(1) # give collector some time + send_and_drain(self.sock, None) + self.sock.close() + sleep(1) # Let the server close their side + super().tearDown() + + def send_and_drain(sock: SocketType, buf: Optional[bytes]) -> None: if buf is not None: sock.send(buf)