From dd524cc893c12c777eeb4505bec031c6e4c7baa9 Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Fri, 29 Nov 2019 11:53:09 -0300 Subject: [PATCH 1/3] 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. --- bin/tests/system/resolver/tests.sh | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/bin/tests/system/resolver/tests.sh b/bin/tests/system/resolver/tests.sh index 11a359be4d..7c7a8ed925 100755 --- a/bin/tests/system/resolver/tests.sh +++ b/bin/tests/system/resolver/tests.sh @@ -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` From a711d6f8c012d65da2635e857e0d6a04b859c428 Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Mon, 2 Dec 2019 19:19:56 -0300 Subject: [PATCH 2/3] Fix resolver tests: prefetch 40/41 These two tests were failing basically because in order for prefetching to happen, the TTL for a given DNS record must be greater than or equal to the prefetch config value + 9. The previous TTL for both records was 10, while prefetch value in configuration was 3, thus making only records with TTL >= 12 elligible for prefetching. TTL value for both records was adjusted to the value 13, and prefetch value was set to 4 (inc by 1), so records with TTL (4 + 9) >= 13 are elligible for prefetching. Adjusting prefetch value to 4 gives the test 1 second more to avoid time problems when sharing resources on a heavy loaded PC. Also prefetch value in settings is now read by the script and used by it to corrrectly calculate the amount of time needed to delay before sending a request to trigger prefetch, adding a bit of flexibility to fine tune the test in the future. --- bin/tests/system/resolver/ns5/named.conf.in | 2 +- bin/tests/system/resolver/ns6/example.net.db.in | 2 +- bin/tests/system/resolver/ns6/fetch.tld.db | 2 +- bin/tests/system/resolver/tests.sh | 12 ++++++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/tests/system/resolver/ns5/named.conf.in b/bin/tests/system/resolver/ns5/named.conf.in index a98290903b..c81a3ba5de 100644 --- a/bin/tests/system/resolver/ns5/named.conf.in +++ b/bin/tests/system/resolver/ns5/named.conf.in @@ -22,7 +22,7 @@ options { recursion yes; dnssec-validation yes; querylog yes; - prefetch 3 9; + prefetch 4 10; }; server 10.53.0.7 { diff --git a/bin/tests/system/resolver/ns6/example.net.db.in b/bin/tests/system/resolver/ns6/example.net.db.in index fa4e96aad8..eab3267b79 100644 --- a/bin/tests/system/resolver/ns6/example.net.db.in +++ b/bin/tests/system/resolver/ns6/example.net.db.in @@ -16,6 +16,6 @@ mail IN A 10.53.0.6 fetch 10 IN TXT A short ttl non-zero 10 IN TXT A short ttl zero 0 IN TXT A zero ttl -$TTL 10 +$TTL 13 ds IN NS ns.ds ns.ds IN A 10.53.0.6 diff --git a/bin/tests/system/resolver/ns6/fetch.tld.db b/bin/tests/system/resolver/ns6/fetch.tld.db index 3754373ec7..b38fd51601 100644 --- a/bin/tests/system/resolver/ns6/fetch.tld.db +++ b/bin/tests/system/resolver/ns6/fetch.tld.db @@ -18,4 +18,4 @@ $TTL 300 @ NS ns.fetch.tld. ns.fetch.tld. A 10.53.0.6 -@ 10 TXT A short ttl +@ 13 TXT A short ttl diff --git a/bin/tests/system/resolver/tests.sh b/bin/tests/system/resolver/tests.sh index 7c7a8ed925..d7e0d0bd4e 100755 --- a/bin/tests/system/resolver/tests.sh +++ b/bin/tests/system/resolver/tests.sh @@ -451,10 +451,13 @@ status=`expr $status + $ret` n=`expr $n + 1` echo_i "check prefetch (${n})" ret=0 +# read prefetch value from config. +PREFETCH=`sed -n "s/[[:space:]]*prefetch \([0-9]\).*/\1/p" ns5/named.conf` $DIG $DIGOPTS @10.53.0.5 fetch.tld txt > dig.out.1.${n} || ret=1 -ttl1=`awk '/"A" "short" "ttl"/ { print $2 - 3 }' dig.out.1.${n}` +ttl1=`awk '/"A" "short" "ttl"/ { print $2 }' dig.out.1.${n}` +interval=$((ttl1 - PREFETCH + 1)) # sleep so we are in prefetch range -sleep ${ttl1:-0} +sleep ${interval:-0} # trigger prefetch $DIG $DIGOPTS @10.53.0.5 fetch.tld txt > dig.out.2.${n} || ret=1 ttl2=`awk '/"A" "short" "ttl"/ { print $2 }' dig.out.2.${n}` @@ -470,9 +473,10 @@ n=`expr $n + 1` echo_i "check prefetch of validated DS's RRSIG TTL is updated (${n})" ret=0 $DIG $DIGOPTS +dnssec @10.53.0.5 ds.example.net ds > dig.out.1.${n} || ret=1 -dsttl1=`awk '$4 == "DS" && $7 == "2" { print $2 - 3 }' dig.out.1.${n}` +dsttl1=`awk '$4 == "DS" && $7 == "2" { print $2 }' dig.out.1.${n}` # sleep so we are in prefetch range -sleep ${dsttl1:-0} +interval=$((dsttl1 - PREFETCH + 1)) +sleep ${interval:-0} # trigger prefetch $DIG $DIGOPTS @10.53.0.5 ds.example.net ds > dig.out.2.${n} || ret=1 dsttl2=`awk '$4 == "DS" && $7 == "2" { print $2 }' dig.out.2.${n}` From 994fc2e8223ed14870047372ca75178fe299295d Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Tue, 3 Dec 2019 10:45:39 -0300 Subject: [PATCH 3/3] Improved prefetch disabled test code Using retry_quiet to test that prefetch is disabled instead of a standard loop with sleep 1 between each iteration. --- bin/tests/system/resolver/tests.sh | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/bin/tests/system/resolver/tests.sh b/bin/tests/system/resolver/tests.sh index d7e0d0bd4e..788e082528 100755 --- a/bin/tests/system/resolver/tests.sh +++ b/bin/tests/system/resolver/tests.sh @@ -474,8 +474,8 @@ echo_i "check prefetch of validated DS's RRSIG TTL is updated (${n})" ret=0 $DIG $DIGOPTS +dnssec @10.53.0.5 ds.example.net ds > dig.out.1.${n} || ret=1 dsttl1=`awk '$4 == "DS" && $7 == "2" { print $2 }' dig.out.1.${n}` -# sleep so we are in prefetch range interval=$((dsttl1 - PREFETCH + 1)) +# sleep so we are in prefetch range sleep ${interval:-0} # trigger prefetch $DIG $DIGOPTS @10.53.0.5 ds.example.net ds > dig.out.2.${n} || ret=1 @@ -496,25 +496,23 @@ 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 }' dig.out.1.${n}` -delay=$((ttl1 - 5)) +interval=$((ttl1 - PREFETCH + 1)) # sleep so we are in expire range -sleep ${delay:-0} +sleep ${interval:-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 +no_prefetch() { + # 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. + $DIG $DIGOPTS @10.53.0.7 fetch.example.net txt > dig.out.2.${n} || return 1 ttl2=`awk '/"A" "short" "ttl"/ { print $2 }' dig.out.2.${n}` # check that prefetch has not occured if [ $ttl2 -ge $tmp_ttl ]; then - ret=1 - break + return 1 fi tmp_ttl=$ttl2 - $PERL -e 'select(undef, undef, undef, 1);' -done - +} +retry_quiet 3 no_prefetch || ret=1 if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret`