From 0a2087eb4342d53d238fcceac9be586a6b2c10ca Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 6 Jan 2016 10:50:22 +0100 Subject: [PATCH] dnsdist: Apply the TCP timeout _before_ trying to connect. In addition to that, we are now more aggressive in stopping dnsdist to avoid getting stuck. Hopefully we should get more useful error messages when the tests fail. Removing usage of the timeout parameter with the same value than the default for clarity. --- regression-tests.dnsdist/dnsdisttests.py | 20 ++++++++++++++++---- regression-tests.dnsdist/test_Advanced.py | 20 ++++++++++---------- regression-tests.dnsdist/test_Basics.py | 16 ++++++++-------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/regression-tests.dnsdist/dnsdisttests.py b/regression-tests.dnsdist/dnsdisttests.py index 81be25024..d6a58571b 100644 --- a/regression-tests.dnsdist/dnsdisttests.py +++ b/regression-tests.dnsdist/dnsdisttests.py @@ -87,10 +87,14 @@ class DNSDistTest(unittest.TestCase): else: cls._dnsdist = subprocess.Popen(dnsdistcmd, close_fds=True) - time.sleep(1) + if 'DNSDIST_FAST_TESTS' in os.environ: + delay = 0.5 + else: + delay = 2 + time.sleep(delay) if cls._dnsdist.poll() is not None: - cls._dnsdist.terminate() + cls._dnsdist.kill() cls._dnsdist.wait() sys.exit(cls._dnsdist.returncode) @@ -111,8 +115,16 @@ class DNSDistTest(unittest.TestCase): @classmethod def tearDownClass(cls): + if 'DNSDIST_FAST_TESTS' in os.environ: + delay = 0.1 + else: + delay = 1 if cls._dnsdist: cls._dnsdist.terminate() + if cls._dnsdist.poll() is None: + time.sleep(delay) + if cls._dnsdist.poll() is None: + cls._dnsdist.kill() cls._dnsdist.wait() @classmethod @@ -240,11 +252,11 @@ class DNSDistTest(unittest.TestCase): if useQueue: cls._toResponderQueue.put(response) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect(("127.0.0.1", cls._dnsDistPort)) - if timeout: sock.settimeout(timeout) + sock.connect(("127.0.0.1", cls._dnsDistPort)) + try: wire = query.to_wire() sock.send(struct.pack("!H", len(wire))) diff --git a/regression-tests.dnsdist/test_Advanced.py b/regression-tests.dnsdist/test_Advanced.py index 2bf52f8c0..9376b81cb 100644 --- a/regression-tests.dnsdist/test_Advanced.py +++ b/regression-tests.dnsdist/test_Advanced.py @@ -224,12 +224,12 @@ class TestAdvancedSpoof(DNSDistTest): '192.0.2.1') expectedResponse.answer.append(rrset) - (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) self.assertTrue(receivedResponse) receivedResponse.id = expectedResponse.id self.assertEquals(expectedResponse, receivedResponse) - (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False) self.assertTrue(receivedResponse) receivedResponse.id = expectedResponse.id self.assertEquals(expectedResponse, receivedResponse) @@ -251,12 +251,12 @@ class TestAdvancedSpoof(DNSDistTest): '2001:DB8::1') expectedResponse.answer.append(rrset) - (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) self.assertTrue(receivedResponse) receivedResponse.id = expectedResponse.id self.assertEquals(expectedResponse, receivedResponse) - (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False) self.assertTrue(receivedResponse) receivedResponse.id = expectedResponse.id self.assertEquals(expectedResponse, receivedResponse) @@ -278,12 +278,12 @@ class TestAdvancedSpoof(DNSDistTest): 'cname.tests.powerdns.com.') expectedResponse.answer.append(rrset) - (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) self.assertTrue(receivedResponse) receivedResponse.id = expectedResponse.id self.assertEquals(expectedResponse, receivedResponse) - (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False) self.assertTrue(receivedResponse) receivedResponse.id = expectedResponse.id self.assertEquals(expectedResponse, receivedResponse) @@ -331,10 +331,10 @@ class TestAdvancedPoolRouting(DNSDistTest): name = 'notpool.tests.powerdns.com.' query = dns.message.make_query(name, 'A', 'IN') - (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) self.assertEquals(receivedResponse, None) - (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False) self.assertEquals(receivedResponse, None) class TestAdvancedRoundRobinLB(DNSDistTest): @@ -475,10 +475,10 @@ class TestAdvancedACL(DNSDistTest): name = 'tests.powerdns.com.' query = dns.message.make_query(name, 'A', 'IN') - (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) self.assertEquals(receivedResponse, None) - (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False) self.assertEquals(receivedResponse, None) class TestAdvancedDelay(DNSDistTest): diff --git a/regression-tests.dnsdist/test_Basics.py b/regression-tests.dnsdist/test_Basics.py index c2b96915f..c54d84143 100644 --- a/regression-tests.dnsdist/test_Basics.py +++ b/regression-tests.dnsdist/test_Basics.py @@ -14,10 +14,10 @@ class TestBasics(DNSDistTest): """ name = 'blockeda.tests.powerdns.org.' query = dns.message.make_query(name, 'A', 'IN') - (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) self.assertEquals(receivedResponse, None) - (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False) self.assertEquals(receivedResponse, None) def testAWithECS(self): @@ -88,11 +88,11 @@ class TestBasics(DNSDistTest): expectedResponse = dns.message.make_response(query) expectedResponse.flags |= dns.flags.TC - (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) receivedResponse.id = expectedResponse.id self.assertEquals(receivedResponse, expectedResponse) - (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False) receivedResponse.id = expectedResponse.id self.assertEquals(receivedResponse, expectedResponse) @@ -138,11 +138,11 @@ class TestBasics(DNSDistTest): expectedResponse = dns.message.make_response(query) expectedResponse.set_rcode(dns.rcode.REFUSED) - (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) receivedResponse.id = expectedResponse.id self.assertEquals(receivedResponse, expectedResponse) - (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False) receivedResponse.id = expectedResponse.id self.assertEquals(receivedResponse, expectedResponse) @@ -158,11 +158,11 @@ class TestBasics(DNSDistTest): expectedResponse = dns.message.make_response(query) expectedResponse.set_rcode(dns.rcode.NOTIMP) - (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) receivedResponse.id = expectedResponse.id self.assertEquals(receivedResponse, expectedResponse) - (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False, timeout=2.0) + (_, receivedResponse) = self.sendTCPQuery(query, response=None, useQueue=False) receivedResponse.id = expectedResponse.id self.assertEquals(receivedResponse, expectedResponse) -- 2.40.0