2019-08-02 15:07:33 +00:00
|
|
|
source common.sh
|
|
|
|
|
|
|
|
clearStore
|
|
|
|
|
2020-07-24 18:38:56 +00:00
|
|
|
garbage1=$(nix store add-path --name garbage1 ./nar-access.sh)
|
|
|
|
garbage2=$(nix store add-path --name garbage2 ./nar-access.sh)
|
|
|
|
garbage3=$(nix store add-path --name garbage3 ./nar-access.sh)
|
2019-08-02 15:07:33 +00:00
|
|
|
|
2019-08-29 10:10:01 +00:00
|
|
|
ls -l $garbage3
|
2019-08-29 10:35:15 +00:00
|
|
|
POSIXLY_CORRECT=1 du $garbage3
|
2019-08-02 15:07:33 +00:00
|
|
|
|
|
|
|
fake_free=$TEST_ROOT/fake-free
|
|
|
|
export _NIX_TEST_FREE_SPACE_FILE=$fake_free
|
|
|
|
echo 1100 > $fake_free
|
|
|
|
|
2020-07-02 13:43:35 +00:00
|
|
|
fifoLock=$TEST_ROOT/fifoLock
|
|
|
|
mkfifo "$fifoLock"
|
|
|
|
|
2019-08-02 15:07:33 +00:00
|
|
|
expr=$(cat <<EOF
|
|
|
|
with import ./config.nix; mkDerivation {
|
|
|
|
name = "gc-A";
|
|
|
|
buildCommand = ''
|
2019-09-03 13:45:32 +00:00
|
|
|
set -x
|
2019-08-02 15:07:33 +00:00
|
|
|
[[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 3 ]]
|
2020-07-02 13:43:35 +00:00
|
|
|
|
2019-08-02 15:07:33 +00:00
|
|
|
mkdir \$out
|
|
|
|
echo foo > \$out/bar
|
2020-07-02 13:43:35 +00:00
|
|
|
|
|
|
|
# Pretend that we run out of space
|
|
|
|
echo 100 > ${fake_free}.tmp1
|
2019-09-03 16:11:43 +00:00
|
|
|
mv ${fake_free}.tmp1 $fake_free
|
2020-07-02 13:43:35 +00:00
|
|
|
|
|
|
|
# Wait for the GC to run
|
|
|
|
for i in {1..20}; do
|
|
|
|
echo ''\${i}...
|
|
|
|
if [[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 1 ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
exit 1
|
2019-08-02 15:07:33 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
|
|
|
|
expr2=$(cat <<EOF
|
|
|
|
with import ./config.nix; mkDerivation {
|
|
|
|
name = "gc-B";
|
|
|
|
buildCommand = ''
|
2019-09-03 13:45:32 +00:00
|
|
|
set -x
|
2019-08-02 15:07:33 +00:00
|
|
|
mkdir \$out
|
|
|
|
echo foo > \$out/bar
|
2020-07-02 13:43:35 +00:00
|
|
|
|
|
|
|
# Wait for the first build to finish
|
|
|
|
cat "$fifoLock"
|
2019-08-02 15:07:33 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
|
2019-11-26 23:05:30 +00:00
|
|
|
nix build --impure -v -o $TEST_ROOT/result-A -L --expr "$expr" \
|
2019-09-03 13:45:32 +00:00
|
|
|
--min-free 1000 --max-free 2000 --min-free-check-interval 1 &
|
2020-07-02 13:43:35 +00:00
|
|
|
pid1=$!
|
2019-09-03 13:45:32 +00:00
|
|
|
|
2019-11-26 23:05:30 +00:00
|
|
|
nix build --impure -v -o $TEST_ROOT/result-B -L --expr "$expr2" \
|
2020-07-02 13:43:35 +00:00
|
|
|
--min-free 1000 --max-free 2000 --min-free-check-interval 1 &
|
|
|
|
pid2=$!
|
2019-08-02 15:07:33 +00:00
|
|
|
|
2020-07-02 13:43:35 +00:00
|
|
|
# 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"
|
2019-08-02 15:07:33 +00:00
|
|
|
|
|
|
|
[[ foo = $(cat $TEST_ROOT/result-A/bar) ]]
|
|
|
|
[[ foo = $(cat $TEST_ROOT/result-B/bar) ]]
|