From 10f9a8e77d504354deafbcf7351a6d46d4528542 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 15 Oct 2021 16:52:37 +0200 Subject: [PATCH] Add a test for the non-blocking GC --- src/libstore/gc.cc | 4 ++++ tests/gc-non-blocking.sh | 33 +++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 3 files changed, 38 insertions(+) create mode 100644 tests/gc-non-blocking.sh diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 648295684..5e8cbf8fc 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -735,6 +735,10 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) } }; + /* Synchronisation point for testing, see tests/gc-concurrent.sh. */ + if (auto p = getEnv("_NIX_TEST_GC_SYNC")) + readFile(*p); + /* Either delete all garbage paths, or just the specified paths (for gcDeleteSpecific). */ if (options.action == GCOptions::gcDeleteSpecific) { diff --git a/tests/gc-non-blocking.sh b/tests/gc-non-blocking.sh new file mode 100644 index 000000000..8b21c6f1c --- /dev/null +++ b/tests/gc-non-blocking.sh @@ -0,0 +1,33 @@ +# Test whether the collector is non-blocking, i.e. a build can run in +# parallel with it. +source common.sh + +needLocalStore "the GC test needs a synchronisation point" + +clearStore + +fifo=$TEST_ROOT/test.fifo +mkfifo "$fifo" + +dummy=$(nix store add-path ./simple.nix) + +running=$TEST_ROOT/running +touch $running + +(_NIX_TEST_GC_SYNC=$fifo nix-store --gc -vvvvv; rm $running) & +pid=$! + +sleep 2 + +outPath=$(nix-build -o "$TEST_ROOT/result" -E " + with import ./config.nix; + mkDerivation { + name = \"non-blocking\"; + buildCommand = \"set -x; test -e $running; mkdir \$out; echo > $fifo\"; + }") + +wait $pid + +(! test -e $running) +(! test -e $dummy) +test -e $outPath diff --git a/tests/local.mk b/tests/local.mk index d88c3a875..8d454ee19 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -4,6 +4,7 @@ nix_tests = \ gc.sh \ ca/gc.sh \ gc-concurrent.sh \ + gc-non-blocking.sh \ gc-auto.sh \ referrers.sh user-envs.sh logging.sh nix-build.sh misc.sh fixed.sh \ gc-runtime.sh check-refs.sh filter-source.sh \