aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-30 14:05:37 +0000
committertv <tv@krebsco.de>2026-11-30 14:22:03 +0000
commitb5a3510bdebd7a0ce2242ad34b7be81d430b7c35 (patch)
tree280541e500ba237f26a8a904f667879fb88f59d6 /pkgs/populate
parent75dab184b999708e6753fc7648cb875cf2e364ec (diff)
tests: bench, timing populate with 100 sources
50 file, 30 symlink, and 20 git sources, delivered once and then twice with nothing to change, locally and to a remote target with 30 ms of delay on its interfaces, which lasts for the rest of the test. So bench is a VM test of its own, which nix-build doesn't build, like smoke.
Diffstat (limited to 'pkgs/populate')
-rw-r--r--pkgs/populate/tests/default.nix10
-rw-r--r--pkgs/populate/tests/scenarios.nix55
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" ];
+
}