From: Remi Gacogne Date: Fri, 7 Jun 2019 08:46:58 +0000 (+0200) Subject: rec: Don't mix time() and gettimeofday() in our unit tests (again) X-Git-Tag: dnsdist-1.4.0-rc1~131^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7884%2Fhead;p=thirdparty%2Fpdns.git rec: Don't mix time() and gettimeofday() in our unit tests (again) We used to set time returned by `sr->getNow()` via `gettimeofday()` and later the one used to compute the RRSIG validity via `time(nullptr)`. It turns out that the second call can return a value lesser than the first one, without the time going backward, making our tests fail. After this commit we base our calculations on the same time value, so it should not fail randomly anymore. --- diff --git a/pdns/recursordist/test-syncres_cc9.cc b/pdns/recursordist/test-syncres_cc9.cc index 61afa24e80..77707d5f29 100644 --- a/pdns/recursordist/test-syncres_cc9.cc +++ b/pdns/recursordist/test-syncres_cc9.cc @@ -349,8 +349,9 @@ BOOST_AUTO_TEST_CASE(test_dnssec_validation_from_negcache_secure) { g_luaconfs.setState(luaconfsCopy); size_t queriesCount = 0; + const time_t fixedNow = sr->getNow().tv_sec; - sr->setAsyncCallback([target,&queriesCount,keys](const ComboAddress& ip, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional& srcmask, boost::optional context, LWResult* res, bool* chained) { + sr->setAsyncCallback([target,&queriesCount,keys,fixedNow](const ComboAddress& ip, const DNSName& domain, int type, bool doTCP, bool sendRDQuery, int EDNS0Level, struct timeval* now, boost::optional& srcmask, boost::optional context, LWResult* res, bool* chained) { queriesCount++; DNSName auth = domain; @@ -364,7 +365,7 @@ BOOST_AUTO_TEST_CASE(test_dnssec_validation_from_negcache_secure) { addRecordToLW(res, domain, QType::SOA, "pdns-public-ns1.powerdns.com. pieter\\.lexis.powerdns.com. 2017032301 10800 3600 604800 3600", DNSResourceRecord::AUTHORITY, 3600); addRRSIG(keys, res->d_records, domain, 300); addNSECRecordToLW(domain, DNSName("z."), { QType::NSEC, QType::RRSIG }, 600, res->d_records); - addRRSIG(keys, res->d_records, domain, 1); + addRRSIG(keys, res->d_records, domain, 1, false, boost::none, boost::none, fixedNow); return 1; } @@ -379,7 +380,7 @@ BOOST_AUTO_TEST_CASE(test_dnssec_validation_from_negcache_secure) { BOOST_CHECK_EQUAL(sr->getValidationState(), Indeterminate); BOOST_REQUIRE_EQUAL(ret.size(), 4); BOOST_CHECK_EQUAL(queriesCount, 1); - /* check that the entry has not been negatively cached */ + /* check that the entry has been negatively cached */ const NegCache::NegCacheEntry* ne = nullptr; BOOST_CHECK_EQUAL(SyncRes::t_sstorage.negcache.size(), 1); BOOST_REQUIRE_EQUAL(SyncRes::t_sstorage.negcache.get(target, QType(QType::A), sr->getNow(), &ne), true);