mirror of
https://github.com/NixOS/nix.git
synced 2025-11-11 21:16: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*
|
||||
}
|
||||
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue