From c03b729319997b4e38c3f586d7c76352228b22e7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 14 Aug 2008 09:26:30 +0000 Subject: [PATCH] * Increase the sleep periods a bit to make the test less likely to fail on slow machines. Of course it would be better if this test wasn't timing dependent... --- src/libstore/gc.cc | 4 ---- tests/gc-concurrent.builder.sh | 7 +++++-- tests/gc-concurrent.sh | 20 +++++++++++--------- tests/gc-concurrent2.builder.sh | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 8f5a1b6e5..a960281ec 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -638,10 +638,6 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) else tempRootsClosed.insert(*i); - /* For testing - see tests/gc-concurrent.sh. */ - if (getenv("NIX_DEBUG_GC_WAIT")) - sleep(2); - /* After this point the set of roots or temporary roots cannot increase, since we hold locks on everything. So everything that is not currently in in `livePaths' or `tempRootsClosed' diff --git a/tests/gc-concurrent.builder.sh b/tests/gc-concurrent.builder.sh index 6b2177ddf..0cd67df3a 100644 --- a/tests/gc-concurrent.builder.sh +++ b/tests/gc-concurrent.builder.sh @@ -1,8 +1,11 @@ mkdir $out echo $(cat $input1/foo)$(cat $input2/bar) > $out/foobar -sleep 5 -mkdir $out || true +sleep 10 + +# $out should not have been GC'ed while we were sleeping, but just in +# case... +mkdir -p $out # Check that the GC hasn't deleted the lock on our output. test -e "$out.lock" diff --git a/tests/gc-concurrent.sh b/tests/gc-concurrent.sh index 446e79f13..6cf652078 100644 --- a/tests/gc-concurrent.sh +++ b/tests/gc-concurrent.sh @@ -1,5 +1,7 @@ source common.sh +$NIX_BIN_DIR/nix-collect-garbage -vvvvv + drvPath1=$($nixinstantiate gc-concurrent.nix) outPath1=$($nixstore -q $drvPath1) @@ -13,15 +15,13 @@ ln -s $drvPath2 "$NIX_STATE_DIR"/gcroots/foo $nixstore -rvv "$drvPath1" & pid1=$! -# Start build #2 in the background after 3 seconds. -(sleep 3 && $nixstore -rvv "$drvPath2") & +# Start build #2 in the background after 6 seconds. +(sleep 6 && $nixstore -rvv "$drvPath2") & pid2=$! -# Run the garbage collector while the build is running. Note: the GC -# sleeps for *another* 2 seconds after acquiring the GC lock. This -# checks whether build #1 -sleep 2 -NIX_DEBUG_GC_WAIT=1 $NIX_BIN_DIR/nix-collect-garbage -vvvvv +# Run the garbage collector while the build is running. +sleep 4 +$NIX_BIN_DIR/nix-collect-garbage -vvvvv # Wait for build #1/#2 to finish. echo waiting for pid $pid1 to finish... @@ -30,11 +30,13 @@ echo waiting for pid $pid2 to finish... wait $pid2 # Check that the root of build #1 and its dependencies haven't been -# deleted. +# deleted. The should not be deleted by the GC because they were +# being built during the GC. cat $outPath1/foobar cat $outPath1/input-2/bar -# Build #2 should have failed because its derivation got garbage collected. +# Check that build #2 has succeeded. It should succeed because the +# derivation is a GC root. cat $outPath2/foobar rm "$NIX_STATE_DIR"/gcroots/foo diff --git a/tests/gc-concurrent2.builder.sh b/tests/gc-concurrent2.builder.sh index f7b6094e8..4bfb33103 100644 --- a/tests/gc-concurrent2.builder.sh +++ b/tests/gc-concurrent2.builder.sh @@ -4,4 +4,4 @@ echo $(cat $input1/foo)$(cat $input2/bar)xyzzy > $out/foobar # Check that the GC hasn't deleted the lock on our output. test -e "$out.lock" -sleep 3 \ No newline at end of file +sleep 6