From 6ac1a991cfb253f87a81551d9eba36c11d816cfe Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 18 Mar 2019 17:24:18 +0100 Subject: [PATCH] auth: Avoid contention issues in the packet cache's unit tests We used to do a retrieval from the cache to compute the hash, but that could have failed due to another thread already having the relevant lock ("deferred-lookup"), resulting the hash value not being updated. --- pdns/test-packetcache_cc.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pdns/test-packetcache_cc.cc b/pdns/test-packetcache_cc.cc index e2e1066e1..bd1670266 100644 --- a/pdns/test-packetcache_cc.cc +++ b/pdns/test-packetcache_cc.cc @@ -156,9 +156,11 @@ try DNSPacket r(false); r.parse((char*)&pak[0], pak.size()); - /* this step is necessary to get a valid hash */ - DNSPacket cached(false); - g_PC->get(&q, &cached); + /* this step is necessary to get a valid hash + we directly compute the hash instead of querying the + cache because 1/ it's faster 2/ no deferred-lookup issues + */ + q.setHash(g_PC->canHashPacket(q.getString())); const unsigned int maxTTL = 3600; g_PC->insert(&q, &r, maxTTL); @@ -212,6 +214,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheThreaded) { pthread_join(tid[i], &res); BOOST_CHECK_EQUAL(PC.size() + S.read("deferred-packetcache-inserts"), 400000); + BOOST_CHECK_EQUAL(S.read("deferred-packetcache-lookup"), 0); BOOST_CHECK_SMALL(1.0*S.read("deferred-packetcache-inserts"), 10000.0); for(int i=0; i < 4; ++i) @@ -224,9 +227,12 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheThreaded) { cerr<<"Hits: "<