about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am12
-rw-r--r--tests/parallel.builder.sh32
-rw-r--r--tests/parallel.nix.in19
-rw-r--r--tests/parallel.sh20
4 files changed, 80 insertions, 3 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ba45a3ad8fd0..d540290b4944 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
\ No newline at end of file
+  locking.nix.in locking.builder.sh \
+  parallel.nix.in parallel.builder.sh
diff --git a/tests/parallel.builder.sh b/tests/parallel.builder.sh
new file mode 100644
index 000000000000..d6d0bedf455a
--- /dev/null
+++ b/tests/parallel.builder.sh
@@ -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
diff --git a/tests/parallel.nix.in b/tests/parallel.nix.in
new file mode 100644
index 000000000000..41d6776d1bbe
--- /dev/null
+++ b/tests/parallel.nix.in
@@ -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;
+}
\ No newline at end of file
diff --git a/tests/parallel.sh b/tests/parallel.sh
new file mode 100644
index 000000000000..7040f7ad91d3
--- /dev/null
+++ b/tests/parallel.sh
@@ -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