diff --git a/tests/functional/common/vars-and-functions.sh.in b/tests/functional/common/vars-and-functions.sh.in index 8fef29f97..f86b44242 100644 --- a/tests/functional/common/vars-and-functions.sh.in +++ b/tests/functional/common/vars-and-functions.sh.in @@ -73,7 +73,7 @@ clearProfiles() { clearStore() { echo "clearing store..." - chmod -R +w "$NIX_STORE_DIR" + chmod -R +w "$NIX_STORE_DIR" || true rm -rf "$NIX_STORE_DIR" mkdir "$NIX_STORE_DIR" rm -rf "$NIX_STATE_DIR" @@ -89,6 +89,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_TEST_DAEMON_PID-}" != '' ]]; then @@ -110,6 +119,7 @@ startDaemon() { fail "Didn’t manage to start the daemon" fi trap "killDaemon" EXIT + trapFunctions[killDaemon]=killDaemon # Save for if daemon is killed NIX_REMOTE_OLD=$NIX_REMOTE export NIX_REMOTE=daemon @@ -132,7 +142,7 @@ killDaemon() { unset _NIX_TEST_DAEMON_PID # Restore old nix remote NIX_REMOTE=$NIX_REMOTE_OLD - trap "" EXIT + trapFunctions[killDaemon]=: } restartDaemon() { diff --git a/tests/functional/gc-external-daemon/common.sh b/tests/functional/gc-external-daemon/common.sh new file mode 100644 index 000000000..2bff94788 --- /dev/null +++ b/tests/functional/gc-external-daemon/common.sh @@ -0,0 +1,6 @@ +source ../common.sh + +enableFeatures "external-gc-daemon" +echo "gc-socket-path = $NIX_GC_SOCKET_PATH" >> "$NIX_CONF_DIR"/nix.conf + +startGcDaemon diff --git a/tests/functional/gc-external-daemon/gc-auto.sh b/tests/functional/gc-external-daemon/gc-auto.sh new file mode 100644 index 000000000..1b50c7ed1 --- /dev/null +++ b/tests/functional/gc-external-daemon/gc-auto.sh @@ -0,0 +1,5 @@ +source common.sh + +cd .. +source ./gc-auto.sh + diff --git a/tests/functional/gc-external-daemon/gc-concurrent.sh b/tests/functional/gc-external-daemon/gc-concurrent.sh new file mode 100644 index 000000000..76b180aac --- /dev/null +++ b/tests/functional/gc-external-daemon/gc-concurrent.sh @@ -0,0 +1,4 @@ +source common.sh + +cd .. +source ./gc-concurrent.sh diff --git a/tests/functional/gc-external-daemon/gc-runtime.sh b/tests/functional/gc-external-daemon/gc-runtime.sh new file mode 100644 index 000000000..0fc5d865d --- /dev/null +++ b/tests/functional/gc-external-daemon/gc-runtime.sh @@ -0,0 +1,5 @@ +source common.sh + +cd .. +source ./gc-runtime.sh + diff --git a/tests/functional/gc-external-daemon/gc.sh b/tests/functional/gc-external-daemon/gc.sh new file mode 100644 index 000000000..6d59d68c2 --- /dev/null +++ b/tests/functional/gc-external-daemon/gc.sh @@ -0,0 +1,4 @@ +source common.sh + +cd .. +source ./gc.sh diff --git a/tests/functional/local.mk b/tests/functional/local.mk index 18eb887cd..f838e89fd 100644 --- a/tests/functional/local.mk +++ b/tests/functional/local.mk @@ -18,6 +18,7 @@ nix_tests = \ flakes/flake-in-submodule.sh \ gc.sh \ nix-collect-garbage-d.sh \ + gc-external-daemon.sh \ remote-store.sh \ legacy-ssh-store.sh \ lang.sh \ diff --git a/tests/gc-external-daemon.sh b/tests/gc-external-daemon.sh new file mode 100644 index 000000000..d0eff3892 --- /dev/null +++ b/tests/gc-external-daemon.sh @@ -0,0 +1,39 @@ +source common.sh + +enableFeatures "external-gc-daemon" + +export NIX_GC_SOCKET_PATH=$TEST_ROOT/gc.socket +startGcDaemon() { + # Start the daemon, wait for the socket to appear. !!! + # ‘nix-daemon’ should have an option to fork into the background. + rm -f $NIX_GC_SOCKET_PATH + $(dirname $(command -v nix))/../libexec/nix/nix-find-roots \ + -l "$NIX_GC_SOCKET_PATH" \ + -d "$NIX_STATE_DIR" \ + -s "$NIX_STORE_DIR" \ + & + for ((i = 0; i < 30; i++)); do + if [[ -S $NIX_GC_SOCKET_PATH ]]; then break; fi + sleep 1 + done + pidGcDaemon=$! + trapFunctions[killGcDaemon]=killGcDaemon +} + +killGcDaemon() { + kill $pidGcDaemon + for i in {0..10}; do + kill -0 $pidGcDaemon || break + sleep 1 + done + kill -9 $pidGcDaemon || true + wait $pidGcDaemon || true + trapFunctions[killGcDaemon]=: +} + +startGcDaemon + +source ./gc.sh +source ./gc-concurrent.sh +source ./gc-runtime.sh +source ./gc-auto.sh