fix: test: Fix an issue with unreachable cache's unit test

The isc_stdtime_now() function used by dns_unreachcache_find() to
check if the entry needs to be expired has a one-second resolution,
and the test sleeps for 1 second and then for the amount of the
expiration interval, which in a worst-case scenario can cause the
test to fail, because the entry was expected to be expired but it
wasn't. Sleep for 2 seconds instead of 1 to avoid the timing
resolution issue.

Closes #5601

Merge branch '5601-unreachable-cache-expire-test-fix' into 'main'

See merge request isc-projects/bind9!11224
This commit is contained in:
Arаm Sаrgsyаn 2025-12-03 10:16:08 +00:00
commit 93fa62c3e0

View file

@ -119,21 +119,26 @@ ISC_LOOP_TEST_IMPL(expire) {
result = dns_unreachcache_find(uc, &dst_addrv4, &src_addrv4);
assert_int_equal(result, ISC_R_SUCCESS);
sleep(1);
/*
* A successful find is expected after two seconds, because the
* expiration time is longer than 2 seconds.
*/
sleep(2);
result = dns_unreachcache_find(uc, &dst_addrv4, &src_addrv4);
assert_int_equal(result, ISC_R_SUCCESS);
/* After the expiration time, it's no longer expected to be found. */
sleep(EXPIRE_MIN_S);
result = dns_unreachcache_find(uc, &dst_addrv4, &src_addrv4);
assert_int_equal(result, ISC_R_NOTFOUND);
/*
* Because of the exponentatl backoff, the new quick addition after the
* Because of the exponential backoff, the new quick addition after the
* previous expiration should expire in 2 x EXPIRE_MIN_S seconds.
*/
dns_unreachcache_add(uc, &dst_addrv4, &src_addrv4);
sleep(1);
sleep(2);
result = dns_unreachcache_find(uc, &dst_addrv4, &src_addrv4);
assert_int_equal(result, ISC_R_SUCCESS);