From: Remi Gacogne Date: Mon, 18 Mar 2019 16:24:18 +0000 (+0100) Subject: auth: Avoid contention issues in the packet cache's unit tests X-Git-Tag: dnsdist-1.4.0-alpha1~50^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6ac1a991cfb253f87a81551d9eba36c11d816cfe;p=thirdparty%2Fpdns.git 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. --- diff --git a/pdns/test-packetcache_cc.cc b/pdns/test-packetcache_cc.cc index e2e1066e19..bd16702662 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: "<