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:
parent
1cd308194f
commit
beac0b49e4
2 changed files with 13 additions and 4 deletions
|
|
@ -82,6 +82,15 @@ clearCacheCache() {
|
||||||
rm -f $TEST_HOME/.cache/nix/binary-cache*
|
rm -f $TEST_HOME/.cache/nix/binary-cache*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare -A trapFunctions
|
||||||
|
|
||||||
|
callTraps() {
|
||||||
|
for f in "${trapFunctions[@]}"; do
|
||||||
|
$f
|
||||||
|
done
|
||||||
|
}
|
||||||
|
trap callTraps EXIT
|
||||||
|
|
||||||
startDaemon() {
|
startDaemon() {
|
||||||
# Don’t start the daemon twice, as this would just make it loop indefinitely
|
# Don’t start the daemon twice, as this would just make it loop indefinitely
|
||||||
if [[ "$NIX_REMOTE" == daemon ]]; then
|
if [[ "$NIX_REMOTE" == daemon ]]; then
|
||||||
|
|
@ -101,7 +110,7 @@ startDaemon() {
|
||||||
if [[ -z ${DAEMON_STARTED+x} ]]; then
|
if [[ -z ${DAEMON_STARTED+x} ]]; then
|
||||||
fail "Didn’t manage to start the daemon"
|
fail "Didn’t manage to start the daemon"
|
||||||
fi
|
fi
|
||||||
trap "killDaemon" EXIT
|
trapFunctions[killDaemon]=killDaemon
|
||||||
export NIX_REMOTE=daemon
|
export NIX_REMOTE=daemon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,7 +122,7 @@ killDaemon() {
|
||||||
done
|
done
|
||||||
kill -9 $pidDaemon 2> /dev/null || true
|
kill -9 $pidDaemon 2> /dev/null || true
|
||||||
wait $pidDaemon || true
|
wait $pidDaemon || true
|
||||||
trap "" EXIT
|
trapFunctions[killDaemon]=:
|
||||||
}
|
}
|
||||||
|
|
||||||
restartDaemon() {
|
restartDaemon() {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ startGcDaemon() {
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
pidGcDaemon=$!
|
pidGcDaemon=$!
|
||||||
trap "killGcDaemon" EXIT
|
trapFunctions[killGcDaemon]=killGcDaemon
|
||||||
}
|
}
|
||||||
|
|
||||||
killGcDaemon() {
|
killGcDaemon() {
|
||||||
|
|
@ -28,7 +28,7 @@ killGcDaemon() {
|
||||||
done
|
done
|
||||||
kill -9 $pidGcDaemon || true
|
kill -9 $pidGcDaemon || true
|
||||||
wait $pidGcDaemon || true
|
wait $pidGcDaemon || true
|
||||||
trap "" EXIT
|
trapFunctions[killGcDaemon]=:
|
||||||
}
|
}
|
||||||
|
|
||||||
startGcDaemon
|
startGcDaemon
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue