git » dnss » commit 9edbd85

tests: Retry external tests

author Alberto Bertogli
2022-11-20 12:42:22 UTC
committer Alberto Bertogli
2022-11-20 12:42:22 UTC
parent 1de3de04821da1b0c450e1bcd0eb022626e39513

tests: Retry external tests

External tests can be quite flaky due to either networking or the
upstream server we're testing against.

To reduce the rate of false negatives, retry external tests once, after
waiting 1s.

tests/external.sh +15 -8

diff --git a/tests/external.sh b/tests/external.sh
index 34512ae..ba69279 100755
--- a/tests/external.sh
+++ b/tests/external.sh
@@ -71,21 +71,21 @@ function resolve() {
 	if ! grep -E -i -q '^example.com.*A'  .dig.log; then
 		echo "----- FAILED"
 		cat .dig.log
-		false
+		return 1
 	fi
 
 	kdig @127.0.0.1:1053 +notcp  example.com a > .dig.log
 	if ! grep -E -i -q '^example.com.*A'  .dig.log; then
 		echo "----- FAILED"
 		cat .dig.log
-		false
+		return 1
 	fi
 
 	kdig @127.0.0.1:1053 +notcp  com.ar NS > .dig.log
 	if ! grep -E -i -q '^com.ar.*NS'  .dig.log; then
 		echo "----- FAILED"
 		cat .dig.log
-		false
+		return 1
 	fi
 
 	# The response exceeds the default UDP size (512b), so it should fall back
@@ -94,12 +94,12 @@ function resolve() {
 	if ! grep -E -i -q '^google.com.*TXT'  .dig.log; then
 		echo "----- FAILED (missing response)"
 		cat .dig.log
-		false
+		return 1
 	fi
 	if ! grep -E -i -q 'retrying over TCP'  .dig.log; then
 		echo "----- FAILED (did not use TCP)"
 		cat .dig.log
-		false
+		return 1
 	fi
 
 	# Same as above, but we explicitly are ok with a 2k response, which
@@ -108,12 +108,12 @@ function resolve() {
 	if ! grep -E -i -q '^google.com.*TXT'  .dig.log; then
 		echo "----- FAILED (missing response)"
 		cat .dig.log
-		false
+		return 1
 	fi
 	if grep -E -i -q 'retrying over TCP'  .dig.log; then
 		echo "----- FAILED (used TCP)"
 		cat .dig.log
-		false
+		return 1
 	fi
 }
 
@@ -226,7 +226,14 @@ do
 	echo "## DoH against $server"
 	dnss -enable_dns_to_https -dns_listen_addr "localhost:1053" \
 		-https_upstream "$server"
-	resolve
+	# Retry once after giving it some time, because the test environment
+	# and/or the server may be flaky.
+	if ! resolve; then
+		echo
+		echo "### Retrying in 1s"
+		sleep 1
+		resolve
+	fi
 	kill $PID
 done