aboutsummaryrefslogtreecommitdiff
path: root/nixos
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-08-14 07:19:03 +0530
committersinanmohd <sinan@sinanmohd.com>2024-08-14 07:35:17 +0530
commitb79e15cb07e8540ccc037f9cb80d3082366e7560 (patch)
tree6a1644512fcee4f254675492239946c89e0f3359 /nixos
parente1cedc07a2bc987f6eac508cd99e92faa62da081 (diff)
nixosTests/dsl: verify assertChosen
Diffstat (limited to 'nixos')
-rw-r--r--nixos/tests/all-tests.nix24
-rw-r--r--nixos/tests/dsl.nix31
2 files changed, 38 insertions, 17 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index 68342d6..158c025 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -1,4 +1,4 @@
-pkgs:
+{ testers }:
let
dsl = ./dsl.nix;
@@ -54,7 +54,7 @@ in
builtins.mapAttrs
(
name: value:
- pkgs.testers.runNixOSTest (
+ testers.runNixOSTest (
{
inherit name;
testScript = ''
@@ -105,12 +105,20 @@ builtins.mapAttrs
sunset-unbuilt-0 = {
imports = [
{
- # all builds
- dag.needBuilds = 9;
- # all builds allowed
- dag.allowBuilds = 5;
- # chosen builds requested
- dag.choseBuilds = 3;
+ dag = {
+ # all builds
+ needBuilds = 9;
+ # all builds allowed
+ allowBuilds = 5;
+ # chosen builds requested
+ choseBuilds = 3;
+
+ nodes = {
+ a.assertChosen = true;
+ b.assertChosen = true;
+ c.assertChosen = true;
+ };
+ };
}
sunset
];
diff --git a/nixos/tests/dsl.nix b/nixos/tests/dsl.nix
index b22c521..63fcfae 100644
--- a/nixos/tests/dsl.nix
+++ b/nixos/tests/dsl.nix
@@ -105,11 +105,11 @@ in
'';
requestExpressions = pkgs.writeText "guest-request-scope.nix" ''
let
- pkgs = import /nix/store/r365xbb4lp3h3vzahr97aysrzd4dysis-yqy82fn77fy3rv7lpwa9m11w3a2nnqg5-source { };
- config = builtins.fromJSON (builtins.readFile /nix/store/4jai0ds3f1kswspwdib1ggxwyikv1jhr-nix-dag.json);
+ pkgs = import ${pkgs.path} { };
+ config = builtins.fromJSON (builtins.readFile ${configJson});
testPkgs = import ${expressions};
in
- pkgs.lib.attrsets.filterAttrs (name: node: !(config.nodes ? ''${name}) || config.nodes.''${name}.request ) testPkgs
+ pkgs.lib.attrsets.filterAttrs (name: node: !(config.nodes ? ''${name}) || (config.nodes.''${name} ? request && config.nodes.''${name}.request)) testPkgs
'';
tester = pkgs.writers.writePython3Bin "dag-test" { } ''
@@ -222,12 +222,27 @@ in
assert len(need_builds) == expected_need_builds, f"{len(need_builds)} != {expected_need_builds}; building {need_builds}"
print("Verified `needBuilds`", file=sys.stderr)
- if config.get("allowBuilds", None) is not None and config.get("choseBuilds", None) is not None:
- p = subprocess.run(["evanix", "${requestExpressions}", "--dry-run", "--solver=highs", "--max-build", str(config["allowBuilds"])], check=True, stdout=subprocess.PIPE)
- output = p.stdout.decode("utf-8")
- evanix_builds = parse_evanix_dry_run(output)
+ evanix_args = ["evanix", "${requestExpressions}", "--dry-run", "--close-unused-fd", "false"]
+ if config.get("allowBuilds", None) is not None:
+ evanix_args.extend(["--solver=highs", "--max-build", str(config["allowBuilds"])])
+
+ evanix = subprocess.run(evanix_args, check=True, stdout=subprocess.PIPE)
+ evanix_output = evanix.stdout.decode("utf-8")
+ evanix_builds = parse_evanix_dry_run(evanix_output)
+
+ if config.get("choseBuilds", None) is not None:
assert len(evanix_builds) == config["choseBuilds"], f"len({evanix_builds}) != choseBuilds"
print("Verified `choseBuilds`", file=sys.stderr)
+
+ hadAssertChosen = False
+ for name, node in nodes.items():
+ if "assertChosen" not in node or not node["assertChosen"]:
+ continue
+ else:
+ hadAssertChosen = True
+ assert name in evanix_builds, f"{name}.assertChosen failed"
+ if hadAssertChosen:
+ print("Verified `assertChosen`", file=sys.stderr)
'';
in
{
@@ -238,8 +253,6 @@ in
(builtins.map ({ name, ... }: scope.${name}))
]
++ [
- expressions
- requestExpressions
pkgs.path
# Cache runCommand's dependencies such as runtimeShell