forked from lix-project/lix
Make the gc-auto 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
c762385457
commit
11ba4ec795
|
@ -13,24 +13,32 @@ fake_free=$TEST_ROOT/fake-free
|
||||||
export _NIX_TEST_FREE_SPACE_FILE=$fake_free
|
export _NIX_TEST_FREE_SPACE_FILE=$fake_free
|
||||||
echo 1100 > $fake_free
|
echo 1100 > $fake_free
|
||||||
|
|
||||||
|
fifoLock=$TEST_ROOT/fifoLock
|
||||||
|
mkfifo "$fifoLock"
|
||||||
|
|
||||||
expr=$(cat <<EOF
|
expr=$(cat <<EOF
|
||||||
with import ./config.nix; mkDerivation {
|
with import ./config.nix; mkDerivation {
|
||||||
name = "gc-A";
|
name = "gc-A";
|
||||||
buildCommand = ''
|
buildCommand = ''
|
||||||
set -x
|
set -x
|
||||||
[[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 3 ]]
|
[[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 3 ]]
|
||||||
|
|
||||||
mkdir \$out
|
mkdir \$out
|
||||||
echo foo > \$out/bar
|
echo foo > \$out/bar
|
||||||
echo 1...
|
|
||||||
sleep 2
|
# Pretend that we run out of space
|
||||||
echo 200 > ${fake_free}.tmp1
|
echo 100 > ${fake_free}.tmp1
|
||||||
mv ${fake_free}.tmp1 $fake_free
|
mv ${fake_free}.tmp1 $fake_free
|
||||||
echo 2...
|
|
||||||
sleep 2
|
# Wait for the GC to run
|
||||||
echo 3...
|
for i in {1..20}; do
|
||||||
sleep 2
|
echo ''\${i}...
|
||||||
echo 4...
|
if [[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 1 ]]; then
|
||||||
[[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 1 ]]
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
exit 1
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
@ -43,15 +51,9 @@ with import ./config.nix; mkDerivation {
|
||||||
set -x
|
set -x
|
||||||
mkdir \$out
|
mkdir \$out
|
||||||
echo foo > \$out/bar
|
echo foo > \$out/bar
|
||||||
echo 1...
|
|
||||||
sleep 2
|
# Wait for the first build to finish
|
||||||
echo 200 > ${fake_free}.tmp2
|
cat "$fifoLock"
|
||||||
mv ${fake_free}.tmp2 $fake_free
|
|
||||||
echo 2...
|
|
||||||
sleep 2
|
|
||||||
echo 3...
|
|
||||||
sleep 2
|
|
||||||
echo 4...
|
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
@ -59,12 +61,19 @@ EOF
|
||||||
|
|
||||||
nix build -v -o $TEST_ROOT/result-A -L "($expr)" \
|
nix build -v -o $TEST_ROOT/result-A -L "($expr)" \
|
||||||
--min-free 1000 --max-free 2000 --min-free-check-interval 1 &
|
--min-free 1000 --max-free 2000 --min-free-check-interval 1 &
|
||||||
pid=$!
|
pid1=$!
|
||||||
|
|
||||||
nix build -v -o $TEST_ROOT/result-B -L "($expr2)" \
|
nix build -v -o $TEST_ROOT/result-B -L "($expr2)" \
|
||||||
--min-free 1000 --max-free 2000 --min-free-check-interval 1
|
--min-free 1000 --max-free 2000 --min-free-check-interval 1 &
|
||||||
|
pid2=$!
|
||||||
|
|
||||||
wait "$pid"
|
# Once the first build is done, unblock the second one.
|
||||||
|
# If the first build fails, we need to postpone the failure to still allow
|
||||||
|
# the second one to finish
|
||||||
|
wait "$pid1" || FIRSTBUILDSTATUS=$?
|
||||||
|
echo "unlock" > $fifoLock
|
||||||
|
( exit ${FIRSTBUILDSTATUS:-0} )
|
||||||
|
wait "$pid2"
|
||||||
|
|
||||||
[[ foo = $(cat $TEST_ROOT/result-A/bar) ]]
|
[[ foo = $(cat $TEST_ROOT/result-A/bar) ]]
|
||||||
[[ foo = $(cat $TEST_ROOT/result-B/bar) ]]
|
[[ foo = $(cat $TEST_ROOT/result-B/bar) ]]
|
||||||
|
|
Loading…
Reference in a new issue