Check that materialize does not limit concurrency (#699)
Adding materialize call to a derivation should not prevent nix form
building it concurrently with other derivations.
This test makes sure that is the case.
commit5a8b3cb5daa624ad47e7fea1625559803eb4ad65
authorHamish Mackenzie <Hamish.Mackenzie@iohk.io>
dateTue 16 Jun 2020, 21:02 (6 years ago)
parentd98b1e3
.buildkite/pipeline.yml+5
@@ -28,3 +28,8 @@ steps:
2828 - ./update-docs.sh
2929 agents:
3030 system: x86_64-linux
31+
32+ - label: 'Make sure materialize function does not limit concurrency'
33+ command:
34+ - nix-build build.nix -A maintainer-scripts.check-materialization-concurrency -o check-materialization-concurrency.sh
35+ - ./check-materialization-concurrency.sh
build.nix+1
@@ -54,6 +54,7 @@ in rec {
5454 { name = "hpack"; path = haskell.haskellPackages.hpack.components.exes.hpack; }
5555 ];
5656 };
57+ check-materialization-concurrency = pkgs.buildPackages.callPackage ./scripts/check-materialization-concurrency/check.nix {};
5758 };
5859
5960 # These are pure parts of maintainer-script so they can be built by hydra
scripts/check-materialization-concurrency/check.nixnew file+23
@@ -0,0 +1,23 @@
1+{ stdenv, writeScript }:
2+
3+with stdenv.lib;
4+
5+writeScript "check-materialization-concurrency.sh" ''
6+ #!${stdenv.shell}
7+
8+ set -euo pipefail
9+
10+ WORK=$(mktemp -d)
11+
12+ # We expect to see both the hello and world derivations to start building
13+ # before either of them finish.
14+ echo EVENT start hello > $WORK/expected.txt
15+ echo EVENT start world >> $WORK/expected.txt
16+ echo EVENT end hello >> $WORK/expected.txt
17+ echo EVENT end world >> $WORK/expected.txt
18+
19+ nix-build -j2 scripts/check-materialization-concurrency --arg n "\"$(date)\"" 2>&1 | grep '^EVENT' > $WORK/actual.txt
20+
21+ diff -u $WORK/expected.txt $WORK/actual.txt
22+''
23+
scripts/check-materialization-concurrency/default.nixnew file+28
@@ -0,0 +1,28 @@
1+{ n }:
2+# This test makes sure that adding materialize function call with no materialized files
3+# does not impact performance by reducing the ability of nix to perform concurrent
4+# builds.
5+let
6+ inherit (import ../../. {}) pkgs;
7+ hello = pkgs.haskell-nix.materialize { materialized = null; } (pkgs.runCommand "hello" {} ''
8+ echo ${n}
9+ echo EVENT start hello
10+ sleep 2
11+ echo EVENT end hello
12+ echo hello > $out
13+ '');
14+ world = pkgs.haskell-nix.materialize { materialized = null; } (pkgs.runCommand "world" {} ''
15+ echo ${n}
16+ echo EVENT start world
17+ sleep 3
18+ echo EVENT end world
19+ echo world > $out
20+ '');
21+ hello-world = pkgs.runCommand "hello-world" {} ''
22+ cat ${hello} > $out
23+ echo ' '
24+ cat ${world} > $out
25+ '';
26+in hello-world
27+
28+