Print logs only once even if fail is called multiple times

This commit is contained in:
ChillerDragon 2024-01-21 16:05:02 +08:00
parent de5a403a25
commit 8b74e2929d

View file

@ -124,6 +124,9 @@ trap cleanup EXIT
function fail() {
local msg="$1"
if [ ! -f "$tmpdir/fail.txt" ]
then
touch "$tmpdir/fail.txt"
# the first tail get swalloed
# idk why so tail twice to ensure
# getting output
@ -143,6 +146,7 @@ function fail() {
echo "[-] end of client log:"
tail "$logdir/client.txt"
fi
fi
echo "$msg"
exit 1
}
@ -151,14 +155,15 @@ function timeout() {
local seconds="$1"
sleep "$seconds"
echo "[-] Timeout -> killing: $testname"
touch timeout.txt
touch "$tmpdir/timeout.txt"
pkill -f "$testname killme"
kill_all_jobs
fail "[-] Timeout"
}
echo "[*] running test '$testname' ..."
[[ -f timeout.txt ]] && rm timeout.txt
[[ -f "$tmpdir/timeout.txt" ]] && rm "$tmpdir"/timeout.txt
[[ -f "$tmpdir/fail.txt" ]] && rm "$tmpdir"/fail.txt
if [[ "$testname" =~ ^client/ ]]
then
echo "ruby client log $(date)" > "$ruby_logfile"
@ -255,7 +260,7 @@ fi
echo "[*] waiting for jobs to finish ..."
wait
if [ -f timeout.txt ]
if [ -f "$tmpdir/timeout.txt" ]
then
echo "[-] Error timeouted"
exit 1