Skip to content

Commit

Permalink
sharness: move timeout eval replacement to flux-sharness
Browse files Browse the repository at this point in the history
  • Loading branch information
trws authored and mergify-bot committed Mar 14, 2020
1 parent 66c5296 commit 5d567ea
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
41 changes: 41 additions & 0 deletions t/sharness.d/flux-sharness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,47 @@ run_timeout() {
perl -e 'use Time::HiRes qw( ualarm ) ; ualarm ((shift @ARGV) * 1000000) ; exec @ARGV or die "$!"' "$@"
}

#
# Replace sharness _test_eval function to provide a global timeout
#

die_on_alarm() {
kill -9 $! > /dev/null 2>&1 # kill currently executing command
echo "Top-level test timed out"
}

test_eval_() {
( # start a subshell in the background to provide a timeout
set -e
parent_pid=$$
i=0
while kill -0 $parent_pid ; do
sleep 1
if test "$i" -gt ${FLUX_TEST_TIMEOUT:-120} ; then
break
fi
i=$(($i+1))
done
kill -ALRM $$ # send ALRM to parent
) &
ALRM=$!
trap die_on_alarm ALRM
# This is a separate function because some tests use
# "return" to end a test_expect_success block early.
case ",$test_prereq," in
*,INTERACTIVE,*)
eval "$*"
;;
*)
eval </dev/null >&3 2>&4 "$*"
;;
esac
ret=$?
trap - ALRM
kill $ALRM >/dev/null 2>&1
return $ret
}

#
# Echo on stdout a reasonable size for a large test session,
# controllable test-wide via env vars FLUX_TEST_SIZE_MIN and
Expand Down
24 changes: 0 additions & 24 deletions t/sharness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -325,27 +325,7 @@ test_pause() {
fi
}

die_on_alarm() {
kill -9 $! > /dev/null 2>&1 # kill currently executing command
echo "Top-level test timed out"
}

test_eval_() {
( # start a subshell in the background to provide a timeout
set -e
parent_pid=$$
i=0
while kill -0 $parent_pid ; do
sleep 1
if test "$i" -gt ${FLUX_TEST_TIMEOUT:-120} ; then
break
fi
i=$(($i+1))
done
kill -ALRM $$ # send ALRM to parent
) &
ALRM=$!
trap die_on_alarm ALRM
# This is a separate function because some tests use
# "return" to end a test_expect_success block early.
case ",$test_prereq," in
Expand All @@ -356,10 +336,6 @@ test_eval_() {
eval </dev/null >&3 2>&4 "$*"
;;
esac
ret=$?
trap - ALRM
kill $ALRM >/dev/null 2>&1
return $ret
}

test_run_() {
Expand Down

0 comments on commit 5d567ea

Please sign in to comment.