1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-12 05:26:02 +01:00

Correctly handle multiple traps in the tests

This commit is contained in:
Théophane Hufschmitt 2022-04-11 10:20:37 +02:00
parent 1cd308194f
commit beac0b49e4
2 changed files with 13 additions and 4 deletions

View file

@ -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() {
# Dont 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 "Didnt 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() {

View file

@ -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