diff options
author | James Coglan <james@neighbourhood.ie> | 2024-06-19 11:39:01 +0200 |
---|---|---|
committer | James Coglan <james@neighbourhood.ie> | 2024-07-23 15:08:31 +0200 |
commit | 7137086fa0a42abb2420354e1e7e1b99372c4bdd (patch) | |
tree | d399bcac96c40f38b492a930092b4debc26f156d | |
parent | resolved: tests for dns_cache_check_conflicts() (diff) | |
download | systemd-7137086fa0a42abb2420354e1e7e1b99372c4bdd.tar.xz systemd-7137086fa0a42abb2420354e1e7e1b99372c4bdd.zip |
resolves: tests for dns_cache_prune()
-rw-r--r-- | src/resolve/test-dns-cache.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/resolve/test-dns-cache.c b/src/resolve/test-dns-cache.c index 0dd69a541d..a597a112ad 100644 --- a/src/resolve/test-dns-cache.c +++ b/src/resolve/test-dns-cache.c @@ -753,6 +753,44 @@ TEST(dns_cache_lookup_mdns_multiple_unshared_responses_are_not_cached) { } /* ================================================================ + * 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() * ================================================================ */ |