From a03a263e3e548da78bbde763c41523dcd03e541e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Vavru=C5=A1a?= <marek.vavrusa@nic.cz> Date: Sun, 7 Jun 2015 14:12:28 +0200 Subject: [PATCH] lib/cache: return records that are going to be expired next second --- lib/cache.c | 4 ++-- tests/test_cache.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cache.c b/lib/cache.c index 9606ce44c..0d69cadf5 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -152,7 +152,7 @@ int kr_cache_peek(struct kr_cache_txn *txn, uint8_t tag, const knot_dname_t *nam } else { /* Check if the record is still valid. */ uint32_t drift = *timestamp - found->timestamp; - if (drift < found->ttl) { + if (drift <= found->ttl) { *timestamp = drift; txn->owner->stats.hit += 1; return kr_ok(); @@ -264,7 +264,7 @@ int kr_cache_materialize(knot_rrset_t *dst, const knot_rrset_t *src, uint32_t dr knot_rdata_t *rd = knot_rdataset_at(&src->rrs, 0); knot_rdata_t *rd_dst = NULL; for (uint16_t i = 0; i < src->rrs.rr_count; ++i) { - if (knot_rdata_ttl(rd) > drift) { + if (knot_rdata_ttl(rd) >= drift) { /* Append record */ if (knot_rdataset_add(&dst->rrs, rd, mm) != 0) { knot_rrset_clear(dst, mm); diff --git a/tests/test_cache.c b/tests/test_cache.c index a629766a3..f72a69a7a 100644 --- a/tests/test_cache.c +++ b/tests/test_cache.c @@ -360,7 +360,7 @@ static void test_query(void **state) /* Test cache read (simulate aged entry) */ static void test_query_aged(void **state) { - uint32_t timestamp = CACHE_TIME + CACHE_TTL; + uint32_t timestamp = CACHE_TIME + CACHE_TTL + 1; knot_rrset_t cache_rr; knot_rrset_init(&cache_rr, global_rr.owner, global_rr.type, global_rr.rclass); -- GitLab