mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
Merge branch 'master' into add-trace
This commit is contained in:
commit
b29a4ea1dc
25 changed files with 176 additions and 95 deletions
|
@ -1,6 +1,6 @@
|
|||
set -e
|
||||
|
||||
export TEST_ROOT=$(realpath ${TMPDIR:-/tmp}/nix-test)
|
||||
export TEST_ROOT=$(realpath ${TMPDIR:-/tmp}/nix-test)/${TEST_NAME:-default}
|
||||
export NIX_STORE_DIR
|
||||
if ! NIX_STORE_DIR=$(readlink -f $TEST_ROOT/store 2> /dev/null); then
|
||||
# Maybe the build directory is symlinked.
|
||||
|
@ -11,6 +11,7 @@ export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
|
|||
export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
|
||||
export NIX_STATE_DIR=$TEST_ROOT/var/nix
|
||||
export NIX_CONF_DIR=$TEST_ROOT/etc
|
||||
export NIX_DAEMON_SOCKET_PATH=$TEST_ROOT/daemon-socket
|
||||
unset NIX_USER_CONF_FILES
|
||||
export _NIX_TEST_SHARED=$TEST_ROOT/shared
|
||||
if [[ -n $NIX_STORE ]]; then
|
||||
|
@ -76,7 +77,7 @@ startDaemon() {
|
|||
rm -f $NIX_STATE_DIR/daemon-socket/socket
|
||||
nix-daemon &
|
||||
for ((i = 0; i < 30; i++)); do
|
||||
if [ -e $NIX_STATE_DIR/daemon-socket/socket ]; then break; fi
|
||||
if [ -e $NIX_DAEMON_SOCKET_PATH ]; then break; fi
|
||||
sleep 1
|
||||
done
|
||||
pidDaemon=$!
|
||||
|
|
|
@ -13,24 +13,32 @@ fake_free=$TEST_ROOT/fake-free
|
|||
export _NIX_TEST_FREE_SPACE_FILE=$fake_free
|
||||
echo 1100 > $fake_free
|
||||
|
||||
fifoLock=$TEST_ROOT/fifoLock
|
||||
mkfifo "$fifoLock"
|
||||
|
||||
expr=$(cat <<EOF
|
||||
with import ./config.nix; mkDerivation {
|
||||
name = "gc-A";
|
||||
buildCommand = ''
|
||||
set -x
|
||||
[[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 3 ]]
|
||||
|
||||
mkdir \$out
|
||||
echo foo > \$out/bar
|
||||
echo 1...
|
||||
sleep 2
|
||||
echo 200 > ${fake_free}.tmp1
|
||||
|
||||
# Pretend that we run out of space
|
||||
echo 100 > ${fake_free}.tmp1
|
||||
mv ${fake_free}.tmp1 $fake_free
|
||||
echo 2...
|
||||
sleep 2
|
||||
echo 3...
|
||||
sleep 2
|
||||
echo 4...
|
||||
[[ \$(ls \$NIX_STORE/*-garbage? | wc -l) = 1 ]]
|
||||
|
||||
# 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
|
||||
'';
|
||||
}
|
||||
EOF
|
||||
|
@ -43,15 +51,9 @@ with import ./config.nix; mkDerivation {
|
|||
set -x
|
||||
mkdir \$out
|
||||
echo foo > \$out/bar
|
||||
echo 1...
|
||||
sleep 2
|
||||
echo 200 > ${fake_free}.tmp2
|
||||
mv ${fake_free}.tmp2 $fake_free
|
||||
echo 2...
|
||||
sleep 2
|
||||
echo 3...
|
||||
sleep 2
|
||||
echo 4...
|
||||
|
||||
# Wait for the first build to finish
|
||||
cat "$fifoLock"
|
||||
'';
|
||||
}
|
||||
EOF
|
||||
|
@ -59,12 +61,19 @@ EOF
|
|||
|
||||
nix build -v -o $TEST_ROOT/result-A -L "($expr)" \
|
||||
--min-free 1000 --max-free 2000 --min-free-check-interval 1 &
|
||||
pid=$!
|
||||
pid1=$!
|
||||
|
||||
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-B/bar) ]]
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
echo "Build started" > "$lockFifo"
|
||||
|
||||
mkdir $out
|
||||
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
|
||||
# case...
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
with import ./config.nix;
|
||||
|
||||
{ lockFifo ? null }:
|
||||
|
||||
rec {
|
||||
|
||||
input1 = mkDerivation {
|
||||
|
@ -16,6 +18,7 @@ rec {
|
|||
name = "gc-concurrent";
|
||||
builder = ./gc-concurrent.builder.sh;
|
||||
inherit input1 input2;
|
||||
inherit lockFifo;
|
||||
};
|
||||
|
||||
test2 = mkDerivation {
|
||||
|
|
|
@ -2,7 +2,10 @@ source common.sh
|
|||
|
||||
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)
|
||||
|
||||
drvPath2=$(nix-instantiate gc-concurrent.nix -A test2)
|
||||
|
@ -22,19 +25,16 @@ ln -s $outPath3 "$NIX_STATE_DIR"/gcroots/foo2
|
|||
nix-store -rvv "$drvPath1" &
|
||||
pid1=$!
|
||||
|
||||
# Start build #2 in the background after 10 seconds.
|
||||
(sleep 10 && nix-store -rvv "$drvPath2") &
|
||||
pid2=$!
|
||||
# Wait for the build of $drvPath1 to start
|
||||
cat $lockFifo1
|
||||
|
||||
# Run the garbage collector while the build is running.
|
||||
sleep 6
|
||||
nix-collect-garbage
|
||||
|
||||
# Wait for build #1/#2 to finish.
|
||||
# Unlock the build of $drvPath1
|
||||
echo "" > $lockFifo1
|
||||
echo waiting for pid $pid1 to finish...
|
||||
wait $pid1
|
||||
echo waiting for pid $pid2 to finish...
|
||||
wait $pid2
|
||||
|
||||
# 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
|
||||
|
@ -42,8 +42,9 @@ wait $pid2
|
|||
cat $outPath1/foobar
|
||||
cat $outPath1/input-2/bar
|
||||
|
||||
# Check that build #2 has succeeded. It should succeed because the
|
||||
# derivation is a GC root.
|
||||
# Check that the build build $drvPath2 succeeds.
|
||||
# It should succeed because the derivation is a GC root.
|
||||
nix-store -rvv "$drvPath2"
|
||||
cat $outPath2/foobar
|
||||
|
||||
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.
|
||||
test -e "$out.lock"
|
||||
|
||||
sleep 6
|
||||
|
|
|
@ -18,6 +18,7 @@ build-users-group =
|
|||
keep-derivations = false
|
||||
sandbox = false
|
||||
experimental-features = nix-command flakes
|
||||
gc-reserved-space = 0
|
||||
include nix.conf.extra
|
||||
EOF
|
||||
|
||||
|
|
|
@ -40,4 +40,4 @@ tests-environment = NIX_REMOTE= $(bash) -e
|
|||
|
||||
clean-files += $(d)/common.sh
|
||||
|
||||
installcheck: $(d)/common.sh $(d)/config.nix $(d)/plugins/libplugintest.$(SO_EXT)
|
||||
test-deps += tests/common.sh tests/config.nix tests/plugins/libplugintest.$(SO_EXT)
|
||||
|
|
|
@ -55,3 +55,10 @@ chmod a+rx $TEST_ROOT/shell.shebang.rb
|
|||
|
||||
output=$($TEST_ROOT/shell.shebang.rb abc ruby)
|
||||
[ "$output" = '-e load("'"$TEST_ROOT"'/shell.shebang.rb") -- abc ruby' ]
|
||||
|
||||
# Test 'nix develop'.
|
||||
nix develop -f shell.nix shellDrv -c bash -c '[[ -n $stdenv ]]'
|
||||
|
||||
# Test 'nix print-dev-env'.
|
||||
source <(nix print-dev-env -f shell.nix shellDrv)
|
||||
[[ -n $stdenv ]]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue