Fix resolver test: prefetch disabled
The previous test had two problems: 1. It wasn't written specifically for testing what it was supposed to: prefetch disabled. 2. It could fail in some circunstances if the computer's load is too high, due to sleeps not taking parallel tests and cpu load into account. The new test is testing prefetch disabled as follows: 1. It asks for a txt record for a given domain and takes note of the record's TTL (which is 10). 2. It sleeps for (TTL - 5) = 5 seconds, having a window of 5 seconds to issue new queries before the record expires from cache. 3. Three(3) queries are executed in a row, with a interval of 1 second between them, and for each query we verify that the TTL in response is less than the previous one, thus ensuring that prefetch is disabled (if it were enabled this record would have been refreshed already and TTL would be >= the first TTL). Having a window of 5 seconds to perform 3 queries with a interval of 1 second between them gives the test a reasonable amount of time to not suffer from a machine with heavy load.
This commit is contained in:
@@ -491,25 +491,26 @@ n=`expr $n + 1`
|
||||
echo_i "check prefetch disabled (${n})"
|
||||
ret=0
|
||||
$DIG $DIGOPTS @10.53.0.7 fetch.example.net txt > dig.out.1.${n} || ret=1
|
||||
ttl1=`awk '/"A" "short" "ttl"/ { print $2 - 2 }' dig.out.1.${n}`
|
||||
ttl1=`awk '/"A" "short" "ttl"/ { print $2 }' dig.out.1.${n}`
|
||||
delay=$((ttl1 - 5))
|
||||
# sleep so we are in expire range
|
||||
sleep ${ttl1:-0}
|
||||
# look for ttl = 1, allow for one miss at getting zero ttl
|
||||
zerotonine="0 1 2 3 4 5 6 7 8 9"
|
||||
for i in $zerotonine $zerotonine $zerotonine $zerotonine
|
||||
do
|
||||
sleep ${delay:-0}
|
||||
tmp_ttl=$ttl1
|
||||
# fetch record and ensure its ttl is in range 0 < ttl < tmp_ttl
|
||||
# since prefetch is disabled, updated ttl must be a lower value than
|
||||
# the previous one.
|
||||
for i in 0 1 3; do
|
||||
$DIG $DIGOPTS @10.53.0.7 fetch.example.net txt > dig.out.2.${n} || ret=1
|
||||
ttl2=`awk '/"A" "short" "ttl"/ { print $2 }' dig.out.2.${n}`
|
||||
test ${ttl2:-2} -eq 1 && break
|
||||
$PERL -e 'select(undef, undef, undef, 0.05);'
|
||||
# check that prefetch has not occured
|
||||
if [ $ttl2 -ge $tmp_ttl ]; then
|
||||
ret=1
|
||||
break
|
||||
fi
|
||||
tmp_ttl=$ttl2
|
||||
$PERL -e 'select(undef, undef, undef, 1);'
|
||||
done
|
||||
test ${ttl2:-2} -eq 1 || ret=1
|
||||
# delay so that any prefetched record will have a lower ttl than expected
|
||||
sleep 3
|
||||
# check that prefetch has not occured
|
||||
$DIG $DIGOPTS @10.53.0.7 fetch.example.net txt > dig.out.3.${n} || ret=1
|
||||
ttl=`awk '/"A" "short" "ttl"/ { print $2 - 2 }' dig.out.3.${n}`
|
||||
test ${ttl:-0} -eq ${ttl1:-1} || ret=1
|
||||
|
||||
if [ $ret != 0 ]; then echo_i "failed"; fi
|
||||
status=`expr $status + $ret`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user