aboutsummaryrefslogtreecommitdiff
path: root/tests/ca
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2021-07-20 06:57:56 +0200
committerregnat <rg@regnat.ovh>2021-07-20 06:57:56 +0200
commit87077739658b35863fb56131fd7099294c181ee5 (patch)
treeffea44c1494c39df65233816dc5b965e91f154f9 /tests/ca
parent1af3f63be53018ab764090acab36e7c5401609cd (diff)
Properly lock the builds of CA derivations
Make sure that we can’t build the same derivation twice at the same time. Fix https://github.com/NixOS/nix/issues/5029
Diffstat (limited to 'tests/ca')
-rwxr-xr-xtests/ca/concurrent-builds.sh18
-rw-r--r--tests/ca/racy.nix15
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/ca/concurrent-builds.sh b/tests/ca/concurrent-builds.sh
new file mode 100755
index 000000000..68441ec76
--- /dev/null
+++ b/tests/ca/concurrent-builds.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+
+# Ensure that we can’t build twice the same derivation concurrently.
+# Regression test for https://github.com/NixOS/nix/issues/5029
+
+source common.sh
+
+sed -i 's/experimental-features .*/& ca-derivations ca-references/' "$NIX_CONF_DIR"/nix.conf
+
+export NIX_TESTS_CA_BY_DEFAULT=1
+
+clearStore
+
+for i in {0..5}; do
+ nix build --no-link --file ./racy.nix &
+done
+
+wait
diff --git a/tests/ca/racy.nix b/tests/ca/racy.nix
new file mode 100644
index 000000000..555a15484
--- /dev/null
+++ b/tests/ca/racy.nix
@@ -0,0 +1,15 @@
+# A derivation that would certainly fail if several builders tried to
+# build it at once.
+
+
+with import ./config.nix;
+
+mkDerivation {
+ name = "simple";
+ buildCommand = ''
+ mkdir $out
+ echo bar >> $out/foo
+ sleep 3
+ [[ "$(cat $out/foo)" == bar ]]
+ '';
+}