From 3731208dc120b5d12f1c5c63ec58bcdb34c42195 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Mon, 24 Jul 2023 16:54:14 -0400 Subject: [PATCH] Adopt GC test for local-overlay store Doesn't yet pass. Fixes are needed. --- tests/overlay-local-store/gc-inner.sh | 57 +++++++++++++++++++++++++++ tests/overlay-local-store/gc.sh | 5 +++ tests/overlay-local-store/local.mk | 1 + 3 files changed, 63 insertions(+) create mode 100644 tests/overlay-local-store/gc-inner.sh create mode 100755 tests/overlay-local-store/gc.sh diff --git a/tests/overlay-local-store/gc-inner.sh b/tests/overlay-local-store/gc-inner.sh new file mode 100644 index 000000000..01ec48b84 --- /dev/null +++ b/tests/overlay-local-store/gc-inner.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +set -eu -o pipefail + +source common.sh + +# Avoid store dir being inside sandbox build-dir +unset NIX_STORE_DIR +unset NIX_STATE_DIR + +storeDirs + +initLowerStore + +mountOverlayfs + +export NIX_REMOTE="$storeB" +stateB="$storeBRoot/nix/var/nix" +outPath=$(nix-build ../hermetic.nix --no-out-link --arg busybox "$busybox" --arg seed 2) + +# Set a GC root. +mkdir -p "$stateB" +rm -f "$stateB"/gcroots/foo +ln -sf $outPath "$stateB"/gcroots/foo + +[ "$(nix-store -q --roots $outPath)" = "$stateB/gcroots/foo -> $outPath" ] + +nix-store --gc --print-roots | grep $outPath +nix-store --gc --print-live | grep $outPath +if nix-store --gc --print-dead | grep -E $outPath$; then false; fi + +nix-store --gc --print-dead + +expect 1 nix-store --delete $outPath +test -e "$storeBRoot/$outPath" + +shopt -s nullglob +for i in $storeBRoot/*; do + if [[ $i =~ /trash ]]; then continue; fi # compat with old daemon + touch $i.lock + touch $i.chroot +done + +nix-collect-garbage + +# Check that the root and its dependencies haven't been deleted. +cat "$storeBRoot/$outPath" + +rm "$stateB"/gcroots/foo + +nix-collect-garbage + +# Check that the output has been GC'd. +test ! -e $outPath + +# Check that the store is empty. +[ "$(ls -1 "$storeBTop" | wc -l)" = "0" ] diff --git a/tests/overlay-local-store/gc.sh b/tests/overlay-local-store/gc.sh new file mode 100755 index 000000000..1e1fb203e --- /dev/null +++ b/tests/overlay-local-store/gc.sh @@ -0,0 +1,5 @@ +source common.sh + +requireEnvironment +setupConfig +execUnshare ./gc-inner.sh diff --git a/tests/overlay-local-store/local.mk b/tests/overlay-local-store/local.mk index 3a6d00bc1..1f8de8f27 100644 --- a/tests/overlay-local-store/local.mk +++ b/tests/overlay-local-store/local.mk @@ -4,6 +4,7 @@ overlay-local-store-tests := \ $(d)/build.sh \ $(d)/bad-uris.sh \ $(d)/add-lower.sh \ + $(d)/gc.sh \ $(d)/verify.sh \ $(d)/optimise.sh