From: Remi Gacogne Date: Wed, 3 Nov 2021 11:01:05 +0000 (+0100) Subject: dnsdist: Fix a race condition in the XFR regression tests X-Git-Tag: dnsdist-1.7.0-beta1~5^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=936dd73ca3ec8fd44f2b57f92946f5f60df2c770;p=thirdparty%2Fpdns.git dnsdist: Fix a race condition in the XFR regression tests --- diff --git a/regression-tests.dnsdist/dnsdisttests.py b/regression-tests.dnsdist/dnsdisttests.py index d4897e8667..011bae3bbf 100644 --- a/regression-tests.dnsdist/dnsdisttests.py +++ b/regression-tests.dnsdist/dnsdisttests.py @@ -274,10 +274,12 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase): conn.send(wire) while multipleResponses: + # do not block, and stop as soon as the queue is empty, either the next response is already here or we are done + # otherwise we might read responses intended for the next connection if fromQueue.empty(): break - response = fromQueue.get(True, cls._queueTimeout) + response = fromQueue.get(False) if not response: break @@ -627,7 +629,7 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase): return (receivedQuery, messages) def setUp(self): - # This function is called before every tests + # This function is called before every test # Clear the responses counters self._responsesCounter.clear() @@ -636,11 +638,7 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase): # Make sure the queues are empty, in case # a previous test failed - while not self._toResponderQueue.empty(): - self._toResponderQueue.get(False) - - while not self._fromResponderQueue.empty(): - self._fromResponderQueue.get(False) + self.clearResponderQueues() super(DNSDistTest, self).setUp() diff --git a/regression-tests.dnsdist/test_AXFR.py b/regression-tests.dnsdist/test_AXFR.py index 8076dd1524..b1f3910788 100644 --- a/regression-tests.dnsdist/test_AXFR.py +++ b/regression-tests.dnsdist/test_AXFR.py @@ -1,5 +1,6 @@ #!/usr/bin/env python import threading +import time import dns from dnsdisttests import DNSDistTest @@ -13,6 +14,7 @@ class TestAXFR(DNSDistTest): _config_template = """ newServer{address="127.0.0.1:%s"} """ + _verboseMode = True @classmethod def startResponders(cls): @@ -25,6 +27,13 @@ class TestAXFR(DNSDistTest): cls._TCPResponder.setDaemon(True) cls._TCPResponder.start() + def setUp(self): + # This function is called before every test + super(TestAXFR, self).setUp() + # make sure the TCP connection handlers from the previous test + # are not going to read our queue + time.sleep(1) + def testOneMessageAXFR(self): """ AXFR: One message @@ -245,7 +254,7 @@ class TestAXFR(DNSDistTest): dns.rdatatype.SOA, 'ns.' + name + ' hostmaster.' + name + ' 3 3600 3600 3600 60') - # the final SOA starts the AXFR, with first an update from 1 to 2 (one removal, two additions) + # the final SOA starts the IXFR, with first an update from 1 to 2 (one removal, two additions) response = dns.message.make_response(query) response.answer.append(finalSoa) # update from 1 to 2