forked from lix-project/lix
Make the gc-concurrent test more reliable
Use a fifo pipe to handle the synchronisation between the different threads rather than relying on delays
This commit is contained in:
parent
1b5aa60767
commit
c762385457
|
@ -1,7 +1,10 @@
|
||||||
|
echo "Build started" > "$lockFifo"
|
||||||
|
|
||||||
mkdir $out
|
mkdir $out
|
||||||
echo $(cat $input1/foo)$(cat $input2/bar) > $out/foobar
|
echo $(cat $input1/foo)$(cat $input2/bar) > $out/foobar
|
||||||
|
|
||||||
sleep 10
|
# Wait for someone to write on the fifo
|
||||||
|
cat "$lockFifo"
|
||||||
|
|
||||||
# $out should not have been GC'ed while we were sleeping, but just in
|
# $out should not have been GC'ed while we were sleeping, but just in
|
||||||
# case...
|
# case...
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
with import ./config.nix;
|
with import ./config.nix;
|
||||||
|
|
||||||
|
{ lockFifo ? null }:
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
|
|
||||||
input1 = mkDerivation {
|
input1 = mkDerivation {
|
||||||
|
@ -16,6 +18,7 @@ rec {
|
||||||
name = "gc-concurrent";
|
name = "gc-concurrent";
|
||||||
builder = ./gc-concurrent.builder.sh;
|
builder = ./gc-concurrent.builder.sh;
|
||||||
inherit input1 input2;
|
inherit input1 input2;
|
||||||
|
inherit lockFifo;
|
||||||
};
|
};
|
||||||
|
|
||||||
test2 = mkDerivation {
|
test2 = mkDerivation {
|
||||||
|
|
|
@ -2,7 +2,10 @@ source common.sh
|
||||||
|
|
||||||
clearStore
|
clearStore
|
||||||
|
|
||||||
drvPath1=$(nix-instantiate gc-concurrent.nix -A test1)
|
lockFifo1=$TEST_ROOT/test1.fifo
|
||||||
|
mkfifo "$lockFifo1"
|
||||||
|
|
||||||
|
drvPath1=$(nix-instantiate gc-concurrent.nix -A test1 --argstr lockFifo "$lockFifo1")
|
||||||
outPath1=$(nix-store -q $drvPath1)
|
outPath1=$(nix-store -q $drvPath1)
|
||||||
|
|
||||||
drvPath2=$(nix-instantiate gc-concurrent.nix -A test2)
|
drvPath2=$(nix-instantiate gc-concurrent.nix -A test2)
|
||||||
|
@ -22,19 +25,16 @@ ln -s $outPath3 "$NIX_STATE_DIR"/gcroots/foo2
|
||||||
nix-store -rvv "$drvPath1" &
|
nix-store -rvv "$drvPath1" &
|
||||||
pid1=$!
|
pid1=$!
|
||||||
|
|
||||||
# Start build #2 in the background after 10 seconds.
|
# Wait for the build of $drvPath1 to start
|
||||||
(sleep 10 && nix-store -rvv "$drvPath2") &
|
cat $lockFifo1
|
||||||
pid2=$!
|
|
||||||
|
|
||||||
# Run the garbage collector while the build is running.
|
# Run the garbage collector while the build is running.
|
||||||
sleep 6
|
|
||||||
nix-collect-garbage
|
nix-collect-garbage
|
||||||
|
|
||||||
# Wait for build #1/#2 to finish.
|
# Unlock the build of $drvPath1
|
||||||
|
echo "" > $lockFifo1
|
||||||
echo waiting for pid $pid1 to finish...
|
echo waiting for pid $pid1 to finish...
|
||||||
wait $pid1
|
wait $pid1
|
||||||
echo waiting for pid $pid2 to finish...
|
|
||||||
wait $pid2
|
|
||||||
|
|
||||||
# Check that the root of build #1 and its dependencies haven't been
|
# Check that the root of build #1 and its dependencies haven't been
|
||||||
# deleted. The should not be deleted by the GC because they were
|
# deleted. The should not be deleted by the GC because they were
|
||||||
|
@ -42,8 +42,9 @@ wait $pid2
|
||||||
cat $outPath1/foobar
|
cat $outPath1/foobar
|
||||||
cat $outPath1/input-2/bar
|
cat $outPath1/input-2/bar
|
||||||
|
|
||||||
# Check that build #2 has succeeded. It should succeed because the
|
# Check that the build build $drvPath2 succeeds.
|
||||||
# derivation is a GC root.
|
# It should succeed because the derivation is a GC root.
|
||||||
|
nix-store -rvv "$drvPath2"
|
||||||
cat $outPath2/foobar
|
cat $outPath2/foobar
|
||||||
|
|
||||||
rm -f "$NIX_STATE_DIR"/gcroots/foo*
|
rm -f "$NIX_STATE_DIR"/gcroots/foo*
|
||||||
|
|
|
@ -3,5 +3,3 @@ echo $(cat $input1/foo)$(cat $input2/bar)xyzzy > $out/foobar
|
||||||
|
|
||||||
# Check that the GC hasn't deleted the lock on our output.
|
# Check that the GC hasn't deleted the lock on our output.
|
||||||
test -e "$out.lock"
|
test -e "$out.lock"
|
||||||
|
|
||||||
sleep 6
|
|
||||||
|
|
Loading…
Reference in a new issue