diff options
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/populate/tests/default.nix | 10 | ||||
| -rw-r--r-- | pkgs/populate/tests/scenarios.nix | 55 |
2 files changed, 62 insertions, 3 deletions
diff --git a/pkgs/populate/tests/default.nix b/pkgs/populate/tests/default.nix index 9693034..b5dffb0 100644 --- a/pkgs/populate/tests/default.nix +++ b/pkgs/populate/tests/default.nix @@ -11,7 +11,9 @@ # target in a single VM test, for checking changes quickly; build it with # nix-build -A smoke. nix-build -A only --argstr only REGEX runs the # scenarios whose names match the regular expression REGEX in a single VM -# test, e.g. --argstr only 'lock-hooks-.*'. +# test, e.g. --argstr only 'lock-hooks-.*'. nix-build -A bench times +# populate with 100 sources, locally and with 30 ms of delay to the target; +# the log shows how long each run takes. { pkgs ? import <nixpkgs> {}, only ? null }: let @@ -82,13 +84,14 @@ let }; # VM tests of those of the groups of scenarios that are, or aren't, - # exhaustive, named after the groups with prefix in front. + # exhaustive, named after the groups with prefix in front. Not bench, + # whose delay would slow the scenarios after it. testsOf = exhaustive: prefix: lib.mapAttrs (name: scenarios: vm (prefix + name) scenarios pkgs.rsync) (lib.filterAttrs (_: scenarios: scenarios != []) (builtins.mapAttrs (_: builtins.filter (scenario: scenario.exhaustive == exhaustive)) - scenarios)); + (removeAttrs scenarios [ "bench" ]))); allScenarios = lib.concatLists (builtins.attrValues scenarios); @@ -144,6 +147,7 @@ assert checkSourceTypes; // { smoke.smoke = vm "smoke" (named "smoke test" (import ./smoke.nix)) pkgs.rsync; only.only = vm "only" onlyScenarios pkgs.rsync; + bench.bench = vm "bench" scenarios.bench pkgs.rsync; } # An attribute set without recurseForDerivations, so nix-build doesn't # build them. diff --git a/pkgs/populate/tests/scenarios.nix b/pkgs/populate/tests/scenarios.nix index 0c0ce9e..7fa0964 100644 --- a/pkgs/populate/tests/scenarios.nix +++ b/pkgs/populate/tests/scenarios.nix @@ -2496,4 +2496,59 @@ in ]) ]) targetKinds; + # A benchmark: 100 sources, 50 file, 30 symlink, and 20 git ones, + # delivered once and then twice with nothing to change, whose times the + # log shows. Locally, and to a remote target with 30 ms of delay on its + # interfaces, which the scenario sets up, and which lasts for the rest + # of the test, so the bench test runs these alone, and nix-build tests + # doesn't. + bench = let + n = lib.fixedWidthNumber 2; + count = lib.range 1; + names = prefix: k: map (i: "${prefix}${n i}") (count k); + sources = + lib.genAttrs (names "f" 50) (name: { file = "/bench/${name}"; }) // + lib.listToAttrs (lib.zipListsWith + (name: target: lib.nameValuePair name { symlink = target; }) + (names "s" 30) (names "f" 30)) // + lib.genAttrs (names "g" 20) (_: { git = { url = gitUrl; ref = gitHead; }; }); + nothingChanged = '' + expect_eq changed "$(record changed)" false + ''; + in map (targetKind: scenario { + name = "bench-${targetKind}"; + inherit targetKind; + # Directories of 11 files each, for the file sources. + prepareDeployer = '' + for i in $(seq -w 1 50); do + if ! test -e /bench/f$i; then + mkdir -p /bench/f$i/sub + for j in $(seq 1 10); do + echo "$i $j" > /bench/f$i/sub/$j + done + echo "$i" > /bench/f$i/top + fi + done + ''; + prepare = lib.optionalString (targetKind == "remote") '' + for dev in $(ls /sys/class/net); do + if test "$dev" != lo; then + tc qdisc replace dev "$dev" root netem delay 30ms + fi + done + ''; + phases = [ + { + inherit sources; + check = '' + test -e "$T"/f50/sub/10 || fail "f50 missing" + expect_eq s30 "$(readlink "$T"/s30)" f30 + expect_eq g20 "$(git -C "$T"/g20 rev-parse HEAD)" ${gitHead} + ''; + } + { inherit sources; check = nothingChanged; } + { inherit sources; check = nothingChanged; } + ]; + }) [ "local" "remote" ]; + } |
