Skip to content

Commit

Permalink
Add Timeout Handling and Fallback in execute_with_timeout Function
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArne committed Aug 8, 2024
1 parent 4b397c9 commit d1ce338
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions .dbwebb/test/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,19 @@ is_valid_suite () {
# $4+ - arguments for bash command.
#
execute_with_timeout () {
timeout --foreground -k $1 $2 "$3" "${@:4}"
status=$?
if [[ $status == 124 ]] || [[ $status == 137 ]]; then
reset -I
printf "\n\033[0;37;41mTest timedout\033[0m. Something took to longer than $2 seconds to finish!\nMaybe you have an infinty loop.\n\n" | tee -a "$LOG"
if command -v timeout &> /dev/null
then
timeout --foreground -k $1 $2 "$3" "${@:4}"
status=$?
if [[ $status == 124 ]] || [[ $status == 137 ]]; then
reset -I
printf "\n\033[0;37;41mTest timed out\033[0m. Something took longer than $2 seconds to finish!\nMaybe you have an infinite loop.\n\n" | tee -a "$LOG"
fi
else
echo "Error: timeout command not found. Please install it to use this script."
echo "For WSL/Linux: sudo apt install timeout"
echo "For macOS: brew install coreutils"
exit 1
fi
return $status
}
Expand Down

0 comments on commit d1ce338

Please sign in to comment.