1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 06:01:48 +02:00

* Add a test for a more subtle race: a process starting after the

temporary root files have been read but creating outputs before the
  store directory has been read.
This commit is contained in:
Eelco Dolstra 2005-01-31 22:01:55 +00:00
parent 207bdcbe86
commit 89c9bc11ab
5 changed files with 85 additions and 20 deletions

View file

@ -34,12 +34,12 @@ fallback.sh: fallback.nix
nix-push.sh: dependencies.nix
nix-pull.sh: dependencies.nix
gc.sh: dependencies.nix
gc-concurrent.sh: gc-concurrent.nix
gc-concurrent.sh: gc-concurrent.nix gc-concurrent2.nix
TESTS = init.sh hash.sh lang.sh simple.sh dependencies.sh locking.sh parallel.sh \
build-hook.sh substitutes.sh substitutes2.sh fallback.sh nix-push.sh gc.sh \
gc-concurrent.sh verify.sh nix-pull.sh
#TESTS = init.sh gc-concurrent.sh
#TESTS = init.sh hash.sh lang.sh simple.sh dependencies.sh locking.sh parallel.sh \
# build-hook.sh substitutes.sh substitutes2.sh fallback.sh nix-push.sh gc.sh \
# gc-concurrent.sh verify.sh nix-pull.sh
TESTS = init.sh gc-concurrent.sh
XFAIL_TESTS =

View file

@ -1,21 +1,34 @@
storeExpr=$($TOP/src/nix-instantiate/nix-instantiate gc-concurrent.nix)
outPath=$($TOP/src/nix-store/nix-store -q $storeExpr)
storeExpr1=$($TOP/src/nix-instantiate/nix-instantiate gc-concurrent.nix)
outPath1=$($TOP/src/nix-store/nix-store -q $storeExpr1)
storeExpr2=$($TOP/src/nix-instantiate/nix-instantiate gc-concurrent2.nix)
outPath2=$($TOP/src/nix-store/nix-store -q $storeExpr2)
ls -l test-tmp/state/temproots
# Start build #1 in the background. It starts immediately.
$TOP/src/nix-store/nix-store -rvv "$storeExpr1" &
pid1=$!
# Start a build in the background.
$TOP/src/nix-store/nix-store -rvv "$storeExpr" &
pid=$!
# Start build #2 in the background after 3 seconds.
(sleep 3 && $TOP/src/nix-store/nix-store -rvv "$storeExpr2") &
pid2=$!
# Run the garbage collector while the build is running.
# 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_BIN_DIR/nix-collect-garbage -vvvvv
NIX_DEBUG_GC_WAIT=1 $NIX_BIN_DIR/nix-collect-garbage -vvvvv
# Wait for the build to finish.
echo waiting for pid $pid to finish...
wait $pid
# Wait for build #1/#2 to finish.
echo waiting for pid $pid1 to finish...
wait $pid1
echo waiting for pid $pid2 to finish...
wait $pid2
# Check that the root and its dependencies haven't been deleted.
cat $outPath/foobar
cat $outPath/input-2/bar
# Check that the root of build #1 and its dependencies haven't been
# deleted.
cat $outPath1/foobar
cat $outPath1/input-2/bar
cat $outPath2/foobar

View file

@ -0,0 +1,9 @@
export PATH=/bin:/usr/bin:$PATH
mkdir $out
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

View file

@ -0,0 +1,25 @@
let {
input1 = derivation {
name = "dependencies-input-1";
system = "@system@";
builder = "@shell@";
args = ["-e" "-x" ./dependencies.builder1.sh];
};
input2 = derivation {
name = "dependencies-input-2";
system = "@system@";
builder = "@shell@";
args = ["-e" "-x" ./dependencies.builder2.sh];
};
body = derivation {
name = "gc-concurrent2";
system = "@system@";
builder = "@shell@";
args = ["-e" "-x" ./gc-concurrent2.builder.sh];
inherit input1 input2;
};
}