From f044ccf7025137ec541e165e7988772f27080a23 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 May 2004 13:56:30 +0000 Subject: [PATCH] * 1000th revision! * A test to verify that locking of output paths (caused by concurrent invocations of Nix) works correctly. --- tests/Makefile.am | 8 ++++++-- tests/locking.builder.sh | 9 +++++++++ tests/locking.nix.in | 18 ++++++++++++++++++ tests/locking.sh | 17 +++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/locking.builder.sh create mode 100644 tests/locking.nix.in create mode 100644 tests/locking.sh diff --git a/tests/Makefile.am b/tests/Makefile.am index 2119221bb..ba45a3ad8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,11 +11,15 @@ TESTS_ENVIRONMENT = TEST_ROOT=$(TEST_ROOT) \ simple.sh: simple.nix dependencies.sh: dependencies.nix +locking.sh: locking.nix -TESTS = init.sh simple.sh dependencies.sh +TESTS = init.sh simple.sh dependencies.sh locking.sh + +XFAIL_TESTS = include ../substitute.mk EXTRA_DIST = $(TESTS) \ simple.nix.in simple.builder.sh \ - dependencies.nix.in dependencies.builder*.sh + dependencies.nix.in dependencies.builder*.sh \ + locking.nix.in locking.builder.sh \ No newline at end of file diff --git a/tests/locking.builder.sh b/tests/locking.builder.sh new file mode 100644 index 000000000..5c3dfdafb --- /dev/null +++ b/tests/locking.builder.sh @@ -0,0 +1,9 @@ +export PATH=/bin:/usr/bin:$PATH + +sleep 3 + +touch $out +# Use `>>'; without proper locking this will cause text duplication. +echo -n $(cat $inputs)$text >> $out + +sleep 2 \ No newline at end of file diff --git a/tests/locking.nix.in b/tests/locking.nix.in new file mode 100644 index 000000000..72070678f --- /dev/null +++ b/tests/locking.nix.in @@ -0,0 +1,18 @@ +let { + + mkDrv = text: inputs: derivation { + name = "locking"; + system = "@system@"; + builder = "@shell@"; + args = ["-e" "-x" ./locking.builder.sh]; + inherit text inputs; + }; + + a = mkDrv "a" []; + b = mkDrv "b" [a]; + c = mkDrv "c" [a b]; + d = mkDrv "d" [a]; + e = mkDrv "e" [c d]; + + body = e; +} \ No newline at end of file diff --git a/tests/locking.sh b/tests/locking.sh new file mode 100644 index 000000000..5728aee93 --- /dev/null +++ b/tests/locking.sh @@ -0,0 +1,17 @@ +storeExpr=$($TOP/src/nix-instantiate/nix-instantiate locking.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