git » chasquid » commit 2c02f0d

test: Make t-20-bad_configs less flaky due to asynchronous logging

author Alberto Bertogli
2023-09-02 13:12:36 UTC
committer Alberto Bertogli
2023-09-02 13:12:36 UTC
parent 888b2df4c1d833bc56e6cb39f691c06e16290da4

test: Make t-20-bad_configs less flaky due to asynchronous logging

The t-20-bad_configs test can sometimes have false positives because
the last line recorded in the log isn't always the one causing the
failure, due to asynchronous logging and in particular in combination
with coverage tests (which alter the os.Exit behaviour subtly).

This patch fixes that by having the tests look at the last 4 lines of
output instead. This is not super pretty, but it should be good enough
to cover for any timing issues that arise in these particular tests.

test/t-20-bad_configs/run.sh +6 -4

diff --git a/test/t-20-bad_configs/run.sh b/test/t-20-bad_configs/run.sh
index a31a194..89255e1 100755
--- a/test/t-20-bad_configs/run.sh
+++ b/test/t-20-bad_configs/run.sh
@@ -33,13 +33,15 @@ for i in c-*; do
 	fi
 
 	# Test that they failed as expected, and not by chance/unrelated error.
-	if ! tail -n 1 ".chasquid-$i.out" \
+	# Look in the last 4 lines, because the fatal error may not be in the
+	# very last one due to asynchronous logging.
+	if ! tail -n 4 ".chasquid-$i.out" \
 	   | grep -q -E "$(cat "$i/.expected-error")"; then
 		echo "$i failed"
-		echo "expected last line to match:"
+		echo "expected last 4 lines to contain:"
 		echo "    '$(cat "$i/.expected-error")'"
-		echo "got last line:"
-		echo "    '$(tail -n 1 ".chasquid-$i.out")'"
+		echo "got last 4 lines:"
+		tail -n 4 ".chasquid-$i.out" | sed -e 's/^/    /g'
 		echo
 		fail "$i: chasquid did not fail as expected"
 	fi