From f0d9b6b783c69562f37e42757bc6528c50e80268 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 25 Mar 2019 17:57:31 +0100 Subject: [PATCH] dnsdist: Add a "lots of TCP connections" regression test --- regression-tests.dnsdist/test_TCPKeepAlive.py | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/regression-tests.dnsdist/test_TCPKeepAlive.py b/regression-tests.dnsdist/test_TCPKeepAlive.py index b0aefbd5e..984c7d1e0 100644 --- a/regression-tests.dnsdist/test_TCPKeepAlive.py +++ b/regression-tests.dnsdist/test_TCPKeepAlive.py @@ -5,9 +5,9 @@ import dns from dnsdisttests import DNSDistTest try: - range = xrange + range = xrange except NameError: - pass + pass class TestTCPKeepAlive(DNSDistTest): """ @@ -18,7 +18,7 @@ class TestTCPKeepAlive(DNSDistTest): _tcpIdleTimeout = 20 _maxTCPQueriesPerConn = 99 - _maxTCPConnsPerClient = 3 + _maxTCPConnsPerClient = 100 _maxTCPConnDuration = 99 _config_template = """ newServer{address="127.0.0.1:%s"} @@ -28,6 +28,7 @@ class TestTCPKeepAlive(DNSDistTest): setMaxTCPConnectionDuration(%s) pc = newPacketCache(100, 86400, 1) getPool(""):setCache(pc) + addAction("largernumberofconnections.tcpka.tests.powerdns.com.", SkipCacheAction()) addAction("refused.tcpka.tests.powerdns.com.", RCodeAction(dnsdist.REFUSED)) addAction("dropped.tcpka.tests.powerdns.com.", DropAction()) addResponseAction("dropped-response.tcpka.tests.powerdns.com.", DropResponseAction()) @@ -204,6 +205,49 @@ class TestTCPKeepAlive(DNSDistTest): conn.close() self.assertEqual(count, 0) + def testTCPKaLargeNumberOfConnections(self): + """ + TCP KeepAlive: Large number of connections + """ + name = 'largernumberofconnections.tcpka.tests.powerdns.com.' + query = dns.message.make_query(name, 'A', 'IN') + expectedResponse = dns.message.make_response(query) + #expectedResponse.set_rcode(dns.rcode.SERVFAIL) + rrset = dns.rrset.from_text(name, + 3600, + dns.rdataclass.IN, + dns.rdatatype.A, + '192.0.2.1') + expectedResponse.answer.append(rrset) + + # number of connections + numConns = 50 + # number of queries per connections + numQueriesPerConn = 4 + + conns = [] + start = time.time() + for idx in range(numConns): + conns.append(self.openTCPConnection()) + + count = 0 + for idx in range(numConns * numQueriesPerConn): + try: + conn = conns[idx % numConns] + self.sendTCPQueryOverConnection(conn, query, response=expectedResponse) + response = self.recvTCPResponseOverConnection(conn) + if response is None: + break + self.assertEquals(expectedResponse, response) + count = count + 1 + except: + pass + + for con in conns: + conn.close() + + self.assertEqual(count, numConns * numQueriesPerConn) + class TestTCPKeepAliveNoDownstreamDrop(DNSDistTest): """ This test makes sure that dnsdist drops the TCP connection -- 2.40.0