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.
This commit is contained in:
Aram Sargsyan 2025-11-06 11:33:41 +00:00 committed by Arаm Sаrgsyаn
parent b378336155
commit 8c8bf4e45d

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);