From: bert hubert Date: Fri, 5 Dec 2014 11:08:52 +0000 (+0100) Subject: add unit tests for new sharded packet cache X-Git-Tag: rec-3.7.0-rc1~146 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fbe23e18ea5f7f6415d8b243fff62bf9294f1f29;p=thirdparty%2Fpdns.git add unit tests for new sharded packet cache --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index c38033ea5d..1db464b7cc 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -855,11 +855,13 @@ testrunner_SOURCES = \ test-md5_hh.cc \ test-misc_hh.cc \ test-nameserver_cc.cc \ + test-packetcache_cc.cc \ test-rcpgenerator_cc.cc \ test-statbag_cc.cc \ test-zoneparser_tng_cc.cc \ testrunner.cc \ test-sha_hh.cc \ + packetcache.cc \ unix_utility.cc \ zoneparser-tng.cc zoneparser-tng.hh diff --git a/pdns/test-packetcache_cc.cc b/pdns/test-packetcache_cc.cc new file mode 100644 index 0000000000..dbb65d0647 --- /dev/null +++ b/pdns/test-packetcache_cc.cc @@ -0,0 +1,135 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_NO_MAIN + +#include +#include +#include "iputils.hh" +#include "nameserver.hh" +#include "statbag.hh" +#include "packetcache.hh" +#include "arguments.hh" +#include +extern StatBag S; + + +BOOST_AUTO_TEST_SUITE(packetcache_cc) + +BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) { + PacketCache PC; + + ::arg().set("max-cache-entries", "Maximum number of cache entries")="1000000"; + ::arg().set("cache-ttl","Seconds to store packets in the PacketCache")="20"; + ::arg().set("recursive-cache-ttl","Seconds to store packets for recursive queries in the PacketCache")="10"; + ::arg().set("negquery-cache-ttl","Seconds to store negative query results in the QueryCache")="60"; + ::arg().set("query-cache-ttl","Seconds to store query results in the QueryCache")="20"; + ::arg().set("recursor","If recursion is desired, IP address of a recursing nameserver")="no"; + + S.declare("deferred-cache-inserts","Amount of cache inserts that were deferred because of maintenance"); + S.declare("deferred-cache-lookup","Amount of cache lookups that were deferred because of maintenance"); + + + BOOST_CHECK_EQUAL(PC.size(), 0); + PC.insert("hello", QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); + BOOST_CHECK_EQUAL(PC.size(), 1); + PC.purge(); + BOOST_CHECK_EQUAL(PC.size(), 0); + + int counter=0; + try { + for(counter = 0; counter < 100000; ++counter) { + PC.insert("hello "+boost::lexical_cast(counter), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); + } + + BOOST_CHECK_EQUAL(PC.size(), counter); + + int delcounter=0; + for(delcounter=0; delcounter < counter/100; ++delcounter) { + PC.purge("hello "+boost::lexical_cast(delcounter)); + } + + BOOST_CHECK_EQUAL(PC.size(), counter-delcounter); + + int matches=0; + string entry; + int expected=counter-delcounter; + for(; delcounter < counter; ++delcounter) { + if(PC.getEntry("hello "+boost::lexical_cast(delcounter), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { + matches++; + } + } + BOOST_CHECK_EQUAL(matches, expected); + BOOST_CHECK_EQUAL(entry, "something"); + } + catch(PDNSException& e) { + cerr<<"Had error: "<insert("hello "+boost::lexical_cast(counter+offset), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); + return 0; +} + catch(PDNSException& e) { + cerr<<"Had error: "<getEntry("hello "+boost::lexical_cast(counter+offset), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { + g_missing++; + } + return 0; +} +catch(PDNSException& e) { + cerr<<"Had error in threadReader: "<