From beac0b49e44532ae784bcd441576988d9514a8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Mon, 11 Apr 2022 10:20:37 +0200 Subject: [PATCH] Correctly handle multiple traps in the tests --- tests/common.sh.in | 13 +++++++++++-- tests/gc-external-daemon.sh | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/common.sh.in b/tests/common.sh.in index 6888b4856..83533fd99 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -82,6 +82,15 @@ clearCacheCache() { rm -f $TEST_HOME/.cache/nix/binary-cache* } +declare -A trapFunctions + +callTraps() { + for f in "${trapFunctions[@]}"; do + $f + done +} +trap callTraps EXIT + startDaemon() { # Don’t start the daemon twice, as this would just make it loop indefinitely if [[ "$NIX_REMOTE" == daemon ]]; then @@ -101,7 +110,7 @@ startDaemon() { if [[ -z ${DAEMON_STARTED+x} ]]; then fail "Didn’t manage to start the daemon" fi - trap "killDaemon" EXIT + trapFunctions[killDaemon]=killDaemon export NIX_REMOTE=daemon } @@ -113,7 +122,7 @@ killDaemon() { done kill -9 $pidDaemon 2> /dev/null || true wait $pidDaemon || true - trap "" EXIT + trapFunctions[killDaemon]=: } restartDaemon() { diff --git a/tests/gc-external-daemon.sh b/tests/gc-external-daemon.sh index ed541f9ed..b8a47cfa2 100644 --- a/tests/gc-external-daemon.sh +++ b/tests/gc-external-daemon.sh @@ -17,7 +17,7 @@ startGcDaemon() { sleep 1 done pidGcDaemon=$! - trap "killGcDaemon" EXIT + trapFunctions[killGcDaemon]=killGcDaemon } killGcDaemon() { @@ -28,7 +28,7 @@ killGcDaemon() { done kill -9 $pidGcDaemon || true wait $pidGcDaemon || true - trap "" EXIT + trapFunctions[killGcDaemon]=: } startGcDaemon