aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/gc-auto.sh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-10-05 12:12:18 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-12-01 12:06:43 -0500
commit30dcc19d1f30fc203be460134c4578509cce704f (patch)
tree6cc32609b9984a2c4d5ecc0cac5cf30609e208b9 /tests/functional/gc-auto.sh
parent72425212657d795dc215b334b7c8c8cd36d06b72 (diff)
Put functional tests in `tests/functional`
I think it is bad for these reasons when `tests/` contains a mix of functional and integration tests - Concepts is harder to understand, the documentation makes a good unit vs functional vs integration distinction, but when the integration tests are just two subdirs within `tests/` this is not clear. - Source filtering in the `flake.nix` is more complex. We need to filter out some of the dirs from `tests/`, rather than simply pick the dirs we want and take all of them. This is a good sign the structure of what we are trying to do is not matching the structure of the files. With this change we have a clean: ```shell-session $ git show 'HEAD:tests' tree HEAD:tests functional/ installer/ nixos/ ``` (cherry picked from commit 68c81c737571794f7246db53fb4774e94fcf4b7e)
Diffstat (limited to 'tests/functional/gc-auto.sh')
-rw-r--r--tests/functional/gc-auto.sh81
1 files changed, 81 insertions, 0 deletions
diff --git a/tests/functional/gc-auto.sh b/tests/functional/gc-auto.sh
new file mode 100644
index 000000000..521d9e539
--- /dev/null
+++ b/tests/functional/gc-auto.sh
@@ -0,0 +1,81 @@
+source common.sh
+
+needLocalStore "“min-free” and “max-free” are daemon options"
+
+clearStore
+
+garbage1=$(nix store add-path --name garbage1 ./nar-access.sh)
+garbage2=$(nix store add-path --name garbage2 ./nar-access.sh)
+garbage3=$(nix store add-path --name garbage3 ./nar-access.sh)
+
+ls -l $garbage3
+POSIXLY_CORRECT=1 du $garbage3
+
+fake_free=$TEST_ROOT/fake-free
+export _NIX_TEST_FREE_SPACE_FILE=$fake_free
+echo 1100 > $fake_free
+
+fifoLock=$TEST_ROOT/fifoLock
+mkfifo "$fifoLock"
+
+expr=$(cat <<EOF
+with import ./config.nix; mkDerivation {
+ name = "gc-A";
+ buildCommand = ''
+ set -x
+ [[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 3 ]]
+
+ mkdir \$out
+ echo foo > \$out/bar
+
+ # Pretend that we run out of space
+ echo 100 > ${fake_free}.tmp1
+ mv ${fake_free}.tmp1 $fake_free
+
+ # Wait for the GC to run
+ for i in {1..20}; do
+ echo ''\${i}...
+ if [[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 1 ]]; then
+ exit 0
+ fi
+ sleep 1
+ done
+ exit 1
+ '';
+}
+EOF
+)
+
+expr2=$(cat <<EOF
+with import ./config.nix; mkDerivation {
+ name = "gc-B";
+ buildCommand = ''
+ set -x
+ mkdir \$out
+ echo foo > \$out/bar
+
+ # Wait for the first build to finish
+ cat "$fifoLock"
+ '';
+}
+EOF
+)
+
+nix build --impure -v -o $TEST_ROOT/result-A -L --expr "$expr" \
+ --min-free 1000 --max-free 2000 --min-free-check-interval 1 &
+pid1=$!
+
+nix build --impure -v -o $TEST_ROOT/result-B -L --expr "$expr2" \
+ --min-free 1000 --max-free 2000 --min-free-check-interval 1 &
+pid2=$!
+
+# Once the first build is done, unblock the second one.
+# If the first build fails, we need to postpone the failure to still allow
+# the second one to finish
+wait "$pid1" || FIRSTBUILDSTATUS=$?
+echo "unlock" > $fifoLock
+( exit ${FIRSTBUILDSTATUS:-0} )
+wait "$pid2"
+
+[[ foo = $(cat $TEST_ROOT/result-A/bar) ]]
+[[ foo = $(cat $TEST_ROOT/result-B/bar) ]]