From: James Coglan Date: Wed, 19 Jun 2024 09:39:01 +0000 (+0100) Subject: resolves: tests for dns_cache_prune() X-Git-Tag: v257-rc1~832^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7137086fa0a42abb2420354e1e7e1b99372c4bdd;p=thirdparty%2Fsystemd.git resolves: tests for dns_cache_prune() --- diff --git a/src/resolve/test-dns-cache.c b/src/resolve/test-dns-cache.c index 0dd69a541d2..a597a112ad6 100644 --- a/src/resolve/test-dns-cache.c +++ b/src/resolve/test-dns-cache.c @@ -752,6 +752,44 @@ TEST(dns_cache_lookup_mdns_multiple_unshared_responses_are_not_cached) { dns_resource_record_unref(rr); } +/* ================================================================ + * dns_cache_prune(), dns_cache_expiry_in_one_second() + * ================================================================ */ + +TEST(dns_cache_prune) { + _cleanup_(dns_cache_unrefp) DnsCache cache = new_cache(); + _cleanup_(put_args_unrefp) PutArgs put_args = mk_put_args(); + DnsResourceKey *key = NULL; + + key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "ns1.example.com"); + ASSERT_NOT_NULL(key); + answer_add_a(&put_args, key, 0xc0a8017f, 1, DNS_ANSWER_CACHEABLE); + dns_resource_key_unref(key); + + key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "ns2.example.com"); + ASSERT_NOT_NULL(key); + answer_add_a(&put_args, key, 0x7f01a8cc, 3, DNS_ANSWER_CACHEABLE); + dns_resource_key_unref(key); + + cache_put(&cache, &put_args); + + dns_cache_prune(&cache); + ASSERT_EQ(dns_cache_size(&cache), 2u); + ASSERT_TRUE(dns_cache_expiry_in_one_second(&cache, now(CLOCK_BOOTTIME))); + + sleep(2); + + dns_cache_prune(&cache); + ASSERT_EQ(dns_cache_size(&cache), 1u); + ASSERT_TRUE(dns_cache_expiry_in_one_second(&cache, now(CLOCK_BOOTTIME))); + + sleep(2); + + dns_cache_prune(&cache); + ASSERT_TRUE(dns_cache_is_empty(&cache)); + ASSERT_FALSE(dns_cache_expiry_in_one_second(&cache, now(CLOCK_BOOTTIME))); +} + /* ================================================================ * dns_cache_check_conflicts() * ================================================================ */