Add some tests for the external gc daemon

This commit is contained in:
Théophane Hufschmitt 2022-04-11 10:20:36 +02:00
parent db23f5cf2d
commit 6d2631f514
8 changed files with 76 additions and 2 deletions

View File

@ -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() {
# Dont start the daemon twice, as this would just make it loop indefinitely
if [[ "${_NIX_TEST_DAEMON_PID-}" != '' ]]; then
@ -110,6 +119,7 @@ startDaemon() {
fail "Didnt 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() {

View File

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

View File

@ -0,0 +1,5 @@
source common.sh
cd ..
source ./gc-auto.sh

View File

@ -0,0 +1,4 @@
source common.sh
cd ..
source ./gc-concurrent.sh

View File

@ -0,0 +1,5 @@
source common.sh
cd ..
source ./gc-runtime.sh

View File

@ -0,0 +1,4 @@
source common.sh
cd ..
source ./gc.sh

View File

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

View File

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