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,24 +124,28 @@ trap cleanup EXIT
function fail() { function fail() {
local msg="$1" local msg="$1"
# the first tail get swalloed if [ ! -f "$tmpdir/fail.txt" ]
# idk why so tail twice to ensure
# getting output
# this is a bit ugly but it works
# maybe a sleep does as well
# or I still did not get flushing
tail "$ruby_logfile" &>/dev/null
if [[ "$testname" =~ ^client/ ]]
then then
echo "[-] end of ruby client log:" touch "$tmpdir/fail.txt"
tail "$ruby_logfile" # the first tail get swalloed
echo "[-] end of server log:" # idk why so tail twice to ensure
tail "$logdir/server.txt" # getting output
else # this is a bit ugly but it works
echo "[-] end of ruby server log:" # maybe a sleep does as well
tail "$ruby_logfile" # or I still did not get flushing
echo "[-] end of client log:" tail "$ruby_logfile" &>/dev/null
tail "$logdir/client.txt" if [[ "$testname" =~ ^client/ ]]
then
echo "[-] end of ruby client log:"
tail "$ruby_logfile"
echo "[-] end of server log:"
tail "$logdir/server.txt"
else
echo "[-] end of ruby server log:"
tail "$ruby_logfile"
echo "[-] end of client log:"
tail "$logdir/client.txt"
fi
fi fi
echo "$msg" echo "$msg"
exit 1 exit 1
@ -151,14 +155,15 @@ function timeout() {
local seconds="$1" local seconds="$1"
sleep "$seconds" sleep "$seconds"
echo "[-] Timeout -> killing: $testname" echo "[-] Timeout -> killing: $testname"
touch timeout.txt touch "$tmpdir/timeout.txt"
pkill -f "$testname killme" pkill -f "$testname killme"
kill_all_jobs kill_all_jobs
fail "[-] Timeout" fail "[-] Timeout"
} }
echo "[*] running test '$testname' ..." 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/ ]] if [[ "$testname" =~ ^client/ ]]
then then
echo "ruby client log $(date)" > "$ruby_logfile" echo "ruby client log $(date)" > "$ruby_logfile"
@ -255,7 +260,7 @@ fi
echo "[*] waiting for jobs to finish ..." echo "[*] waiting for jobs to finish ..."
wait wait
if [ -f timeout.txt ] if [ -f "$tmpdir/timeout.txt" ]
then then
echo "[-] Error timeouted" echo "[-] Error timeouted"
exit 1 exit 1