* A test to verify that Nix executes build jobs in parallel, if

possible.

  This test fails right now because this hasn't been implemented right
  now.  Yes, I'm doing Test-Driven Development! ;-)
This commit is contained in:
Eelco Dolstra 2004-05-04 17:04:17 +00:00
parent f044ccf702
commit a9858c9f26
5 changed files with 81 additions and 3 deletions

View File

@ -1,5 +1,6 @@
%: %.in Makefile
sed \
-e "s^@extra1\@^$(extra1)^g" \
-e "s^@prefix\@^$(prefix)^g" \
-e "s^@bindir\@^$(bindir)^g" \
-e "s^@sysconfdir\@^$(sysconfdir)^g" \

View File

@ -1,5 +1,7 @@
TEST_ROOT = $(shell pwd)/test-tmp
extra1 = $(TEST_ROOT)/shared
TESTS_ENVIRONMENT = TEST_ROOT=$(TEST_ROOT) \
NIX_STORE_DIR=$(TEST_ROOT)/store \
NIX_DATA_DIR=$(TEST_ROOT)/data \
@ -7,19 +9,23 @@ TESTS_ENVIRONMENT = TEST_ROOT=$(TEST_ROOT) \
NIX_STATE_DIR=$(TEST_ROOT)/state \
NIX_DB_DIR=$(TEST_ROOT)/db \
TOP=$(shell pwd)/.. \
SHARED=$(extra1) \
$(SHELL) -e -x
simple.sh: simple.nix
dependencies.sh: dependencies.nix
locking.sh: locking.nix
parallel.sh: parallel.nix
TESTS = init.sh simple.sh dependencies.sh locking.sh
TESTS = init.sh simple.sh dependencies.sh parallel.sh
#locking.sh parallel.sh
XFAIL_TESTS =
XFAIL_TESTS = parallel.sh
include ../substitute.mk
EXTRA_DIST = $(TESTS) \
simple.nix.in simple.builder.sh \
dependencies.nix.in dependencies.builder*.sh \
locking.nix.in locking.builder.sh
locking.nix.in locking.builder.sh \
parallel.nix.in parallel.builder.sh

32
tests/parallel.builder.sh Normal file
View File

@ -0,0 +1,32 @@
echo "DOING $text"
export PATH=/bin:/usr/bin:$PATH
# increase counter
while ! ln -s x $shared.lock; do
sleep 1
done
test -f $shared.cur || echo 0 > $shared.cur
test -f $shared.max || echo 0 > $shared.max
new=$(($(cat $shared.cur) + 1))
if test $new -gt $(cat $shared.max); then
echo $new > $shared.max
fi
echo $new > $shared.cur
rm $shared.lock
echo -n $(cat $inputs)$text > $out
sleep 3
# decrease counter
while ! ln -s x $shared.lock; do
sleep 1
done
test -f $shared.cur || echo 0 > $shared.cur
echo $(($(cat $shared.cur) - 1)) > $shared.cur
rm $shared.lock

19
tests/parallel.nix.in Normal file
View File

@ -0,0 +1,19 @@
let {
mkDrv = text: inputs: derivation {
name = "parallel";
system = "@system@";
builder = "@shell@";
args = ["-e" "-x" ./parallel.builder.sh];
shared = "@extra1@";
inherit text inputs;
};
a = mkDrv "a" [];
b = mkDrv "b" [a];
c = mkDrv "c" [b];
d = mkDrv "d" [c];
e = mkDrv "e" [b c d];
body = e;
}

20
tests/parallel.sh Normal file
View File

@ -0,0 +1,20 @@
storeExpr=$($TOP/src/nix-instantiate/nix-instantiate parallel.nix)
echo "store expr is $storeExpr"
for i in $(seq 1 5); do
echo "WORKER $i"
$TOP/src/nix-store/nix-store -rvvB "$storeExpr" &
done
sleep 5
outPath=$($TOP/src/nix-store/nix-store -qnfvvvvv "$storeExpr")
echo "output path is $outPath"
text=$(cat "$outPath")
if test "$text" != "aabcade"; then exit 1; fi
if test "$(cat $SHARED.cur)" != 0; then exit 1; fi
if test "$(cat $SHARED.max)" != 3; then exit 1; fi