mirror of
https://github.com/NixOS/nix.git
synced 2024-11-26 00:32:28 +00:00
Add some tests for the external gc daemon
This commit is contained in:
parent
db23f5cf2d
commit
6d2631f514
@ -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() {
|
||||
|
6
tests/functional/gc-external-daemon/common.sh
Normal file
6
tests/functional/gc-external-daemon/common.sh
Normal 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
|
5
tests/functional/gc-external-daemon/gc-auto.sh
Normal file
5
tests/functional/gc-external-daemon/gc-auto.sh
Normal file
@ -0,0 +1,5 @@
|
||||
source common.sh
|
||||
|
||||
cd ..
|
||||
source ./gc-auto.sh
|
||||
|
4
tests/functional/gc-external-daemon/gc-concurrent.sh
Normal file
4
tests/functional/gc-external-daemon/gc-concurrent.sh
Normal file
@ -0,0 +1,4 @@
|
||||
source common.sh
|
||||
|
||||
cd ..
|
||||
source ./gc-concurrent.sh
|
5
tests/functional/gc-external-daemon/gc-runtime.sh
Normal file
5
tests/functional/gc-external-daemon/gc-runtime.sh
Normal file
@ -0,0 +1,5 @@
|
||||
source common.sh
|
||||
|
||||
cd ..
|
||||
source ./gc-runtime.sh
|
||||
|
4
tests/functional/gc-external-daemon/gc.sh
Normal file
4
tests/functional/gc-external-daemon/gc.sh
Normal file
@ -0,0 +1,4 @@
|
||||
source common.sh
|
||||
|
||||
cd ..
|
||||
source ./gc.sh
|
@ -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 \
|
||||
|
39
tests/gc-external-daemon.sh
Normal file
39
tests/gc-external-daemon.sh
Normal 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
|
Loading…
Reference in New Issue
Block a user