- print(srvname, "terminated with return code", p.exitcode)
- for sfx in (".pub", ".pul"):
- unlink(self.tmpfilebase + sfx)
+ self.assertEqual(
+ p.exitcode,
+ 0,
+ f"{srvname} terminated with return code {p.exitcode}",
+ )
+ for sfx in (
+ "",
+ ".pub",
+ ".rect.pub",
+ ".pul",
+ ".storage.sqlite",
+ ".opencellid.sqlite",
+ ):
+ try:
+ unlink(self.tmpfilebase + sfx)
+ except OSError:
+ 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)
+ try:
+ sock.recv(4096, MSG_DONTWAIT)
+ except BlockingIOError:
+ pass