Skip to content

Commit 61f4bf3

Browse files
committed
fix(ci): improve trap handling in regression and test scripts
Refactor trap usage in .github/regression.sh to use a variable for the error trap string, ensuring proper quoting and shellcheck compliance. Enhance cleanup logic to ignore further interrupts and errors during cleanup, and disable unnecessary traps after tests finish. In .github/run_tests.sh, add --foreground to the timeout command to ensure proper signal handling when running pytest with a session timeout.
1 parent afd7734 commit 61f4bf3

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

.github/regression.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
# shellcheck shell=bash disable=SC2317
33

44
set -Eeuo pipefail
5-
trap 'echo "Error at line $LINENO"' ERR
5+
6+
# shellcheck disable=SC2016
7+
basic_err_string='echo "Error at line $LINENO"'
8+
# shellcheck disable=SC2064
9+
trap "$basic_err_string" ERR
610

711
nix --version
812
df -h .
@@ -188,6 +192,12 @@ _cleanup_testnet_on_interrupt() {
188192
# cleanup on Ctrl+C or error
189193
# shellcheck disable=SC2329
190194
_interrupted() {
195+
# Ignore further interrupts and errors during cleanup
196+
trap '' SIGINT
197+
# shellcheck disable=SC2064
198+
trap "$basic_err_string" ERR
199+
set +e
200+
191201
# Do testnet cleanup only on interrupted testrun. When not interrupted,
192202
# cleanup is done as part of a testrun.
193203
_cleanup_testnet_on_interrupt || :
@@ -238,7 +248,7 @@ MON_PID=$!
238248
239249
# ensure cleanup on ANY exit (success, error, Ctrl-C, set -e, etc.)
240250
# shellcheck disable=SC2064
241-
trap "echo 'Stopping monitor'; kill $MON_PID 2>/dev/null || true" EXIT
251+
trap "echo 'Stopping monitor'; kill ${MON_PID:-} 2>/dev/null || true" EXIT
242252
243253
# Run tests and generate report
244254
@@ -283,7 +293,13 @@ if [ "${KEEP_CLUSTERS_RUNNING:-""}" = 1 ]; then
283293
read -r
284294
fi
285295

296+
# redefine the ERR trap to avoid interfering with cleanup
297+
# shellcheck disable=SC2064
298+
trap "$basic_err_string" ERR
299+
# ignore Ctrl+C during cleanup
300+
trap '' SIGINT
286301
_cleanup
302+
trap - SIGINT
287303

288304
# prepare artifacts for upload in GitHub Actions
289305
if [ -n "${GITHUB_ACTIONS:-""}" ]; then

.github/run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ EOF
5454

5555
run_pytest() {
5656
if [ -n "${SESSION_TIMEOUT:-}" ]; then
57-
local -a timeout_arr=( "--signal=INT" "--kill-after=0" "$SESSION_TIMEOUT" )
57+
local -a timeout_arr=( "--foreground" "--signal=INT" "--kill-after=0" "$SESSION_TIMEOUT" )
5858
echo "Running: PYTEST_ADDOPTS='${PYTEST_ADDOPTS:-}' timeout ${timeout_arr[*]} pytest $*"
5959
timeout "${timeout_arr[@]}" pytest "$@"
6060
else

0 commit comments

Comments
 (0)