]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix a race condition in the XFR regression tests
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 3 Nov 2021 11:01:05 +0000 (12:01 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 8 Nov 2021 09:26:12 +0000 (10:26 +0100)
regression-tests.dnsdist/dnsdisttests.py
regression-tests.dnsdist/test_AXFR.py

index d4897e86673beb18413f22490d5d838a6e80d42a..011bae3bbf364f3a272953219b7377cb98d32c58 100644 (file)
@@ -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()
 
index 8076dd1524af84dc807a96616a6b5cecf4f00ef8..b1f3910788c2041e985e9d6fd551f9cc2d6f7fda 100644 (file)
@@ -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