X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=test%2Ftest_fuzz.py;h=d937c95a3dd216a064e2718ce38dbdf68b391b23;hb=84c11e46ef8ec36824b0d040972de37e41943b5d;hp=6dea449af255ae5c8ad8eabbe5d657880543ab34;hpb=b1dd80b69cf259d4ad3a26c9cf8f9440e3ace0fd;p=loctrkd.git diff --git a/test/test_fuzz.py b/test/test_fuzz.py index 6dea449..d937c95 100644 --- a/test/test_fuzz.py +++ b/test/test_fuzz.py @@ -1,18 +1,20 @@ """ Send junk to the collector """ from random import Random -from socket import getaddrinfo, socket, AF_INET6, SOCK_STREAM -from unittest import TestCase +from socket import getaddrinfo, socket, AF_INET6, MSG_DONTWAIT, SOCK_STREAM +import unittest +from .common import TestWithServers REPEAT: int = 1000000 -class Fuzz(TestCase): - def setUp(self) -> None: +class Fuzz(TestWithServers): + def setUp(self, *args: str) -> None: + super().setUp("collector") self.rnd = Random() for fam, typ, pro, cnm, skadr in getaddrinfo( "::1", - 4303, + self.conf.getint("collector", "port"), family=AF_INET6, type=SOCK_STREAM, ): @@ -22,9 +24,19 @@ class Fuzz(TestCase): def tearDown(self) -> None: self.sock.close() + print("finished fuzzing") + super().tearDown() def test_fuzz(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 + + +if __name__ == "__main__": + unittest.main()