Add a test for the non-blocking GC

This commit is contained in:
Eelco Dolstra 2021-10-15 16:52:37 +02:00
parent ac54c6faa6
commit 10f9a8e77d
3 changed files with 38 additions and 0 deletions

View file

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

33
tests/gc-non-blocking.sh Normal file
View file

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

View file

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