X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=test%2Ftest_fuzz.py;h=0456fda0352ddede2b315fb351bf431b500929ba;hb=f075dbd6eea0e7326d68fd15a103d668baf67c10;hp=d937c95a3dd216a064e2718ce38dbdf68b391b23;hpb=4b4c5078f02af922758afa195e8fcdcaccab950d;p=loctrkd.git diff --git a/test/test_fuzz.py b/test/test_fuzz.py index d937c95..0456fda 100644 --- a/test/test_fuzz.py +++ b/test/test_fuzz.py @@ -2,6 +2,8 @@ from random import Random from socket import getaddrinfo, socket, AF_INET6, MSG_DONTWAIT, SOCK_STREAM +from time import sleep +from typing import Optional import unittest from .common import TestWithServers @@ -23,19 +25,31 @@ class Fuzz(TestWithServers): self.sock.connect(skadr) def tearDown(self) -> None: + sleep(1) # give collector some time + self._send_and_drain(None) self.sock.close() print("finished fuzzing") super().tearDown() - def test_fuzz(self) -> None: + def _send_and_drain(self, buf: Optional[bytes]) -> None: + if buf is not None: + self.sock.send(buf) + try: + self.sock.recv(4096, MSG_DONTWAIT) + except BlockingIOError: + pass + + def test_stream(self) -> None: for _ in range(REPEAT): size = self.rnd.randint(1, 5000) buf = self.rnd.randbytes(size) - self.sock.send(buf) - try: - self.sock.recv(4096, MSG_DONTWAIT) - except BlockingIOError: - pass + self._send_and_drain(buf) + + def test_msgs(self) -> None: + for _ in range(REPEAT): + size = self.rnd.randint(0, 300) + buf = b"xx" + self.rnd.randbytes(size) + b"\r\n" + self._send_and_drain(buf) if __name__ == "__main__":