From: Remi Gacogne Date: Thu, 10 Apr 2025 14:04:04 +0000 (+0200) Subject: dnsdist: Add a regression test for cache lookups w/ unavailable cache-only backends X-Git-Tag: dnsdist-2.0.0-alpha2~82^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a36a3e9bfc3a50735cbe63252fadd46ba984ba55;p=thirdparty%2Fpdns.git dnsdist: Add a regression test for cache lookups w/ unavailable cache-only backends --- diff --git a/regression-tests.dnsdist/test_Caching.py b/regression-tests.dnsdist/test_Caching.py index 0f0f1195b4..76c85059d0 100644 --- a/regression-tests.dnsdist/test_Caching.py +++ b/regression-tests.dnsdist/test_Caching.py @@ -1151,15 +1151,19 @@ class TestCachingStale(DNSDistTest): _consoleKey = DNSDistTest.generateConsoleKey() _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') _staleCacheTTL = 60 - _config_params = ['_staleCacheTTL', '_consoleKeyB64', '_consolePort', '_testServerPort'] + _config_params = ['_staleCacheTTL', '_consoleKeyB64', '_consolePort', '_testServerPort', '_testServerPort'] _config_template = """ pc = newPacketCache(100, {maxTTL=86400, minTTL=1, temporaryFailureTTL=0, staleTTL=%d}) getPool(""):setCache(pc) + getPool("tcp-only"):setCache(pc) setStaleCacheEntriesTTL(600) setKey("%s") controlSocket("127.0.0.1:%d") newServer{address="127.0.0.1:%d"} + newServer{address="127.0.0.1:%d", tcpOnly=true, pool='tcp-only'} + addAction(QNameRule('stale-tcp-only.cache.tests.powerdns.com.'), PoolAction('tcp-only')) """ + def testCacheStale(self): """ Cache: Cache entry, set backend down, get stale entry @@ -1207,6 +1211,53 @@ class TestCachingStale(DNSDistTest): self.assertEqual(total, misses) + def testCacheStaleTCPOnly(self): + """ + Cache: Cache entry from TCP-only backend, set backend down, get stale entry + + """ + misses = 0 + ttl = 2 + name = 'stale-tcp-only.cache.tests.powerdns.com.' + query = dns.message.make_query(name, 'A', 'IN') + response = dns.message.make_response(query) + rrset = dns.rrset.from_text(name, + ttl, + dns.rdataclass.IN, + dns.rdatatype.A, + '127.0.0.1') + response.answer.append(rrset) + + # Miss + (receivedQuery, receivedResponse) = self.sendUDPQuery(query, response) + self.assertTrue(receivedQuery) + self.assertTrue(receivedResponse) + receivedQuery.id = query.id + self.assertEqual(query, receivedQuery) + self.assertEqual(response, receivedResponse) + misses += 1 + + # next queries should hit the cache + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) + self.assertEqual(receivedResponse, response) + + # ok, we mark the backend as down + self.sendConsoleCommand("getServer(1):setDown()") + # and we wait for the entry to expire + time.sleep(ttl + 1) + + # we should get a cached, stale, entry + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) + self.assertEqual(receivedResponse, response) + for an in receivedResponse.answer: + self.assertEqual(an.ttl, self._staleCacheTTL) + + total = 0 + for key in self._responsesCounter: + total += self._responsesCounter[key] + + self.assertEqual(total, misses) + class TestCachingStaleExpunged(DNSDistTest): _consoleKey = DNSDistTest.generateConsoleKey()