about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorMichael Raskin <7c6f434c@mail.ru>2021-05-23 18:08:46 +0000
committerGitHub <noreply@github.com>2021-05-23 18:08:46 +0000
commitab51a2dbd6b5fcc8f6ae467075a2863ecac7c7d0 (patch)
tree313cc6a9a848020b5f6ffb82ac8ba129500c84d7 /nixos
parentde84bd18d750fcc55ffa8052377a168f8ba2bad1 (diff)
parent9cb76c21ee134b23e72b09d0043e94ab89f83338 (diff)
Merge pull request #123926 from pschyska/master
nixos/atop: Add defaultText to types.package options, Fix timing-related test failures.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/programs/atop.nix2
-rw-r--r--nixos/tests/atop.nix37
2 files changed, 32 insertions, 7 deletions
diff --git a/nixos/modules/programs/atop.nix b/nixos/modules/programs/atop.nix
index 47597a0a4d4bb..b45eb16e3eaf6 100644
--- a/nixos/modules/programs/atop.nix
+++ b/nixos/modules/programs/atop.nix
@@ -19,6 +19,7 @@ in
       package = mkOption {
         type = types.package;
         default = pkgs.atop;
+        defaultText = "pkgs.atop";
         description = ''
           Which package to use for Atop.
         '';
@@ -36,6 +37,7 @@ in
         package = mkOption {
           type = types.package;
           default = config.boot.kernelPackages.netatop;
+          defaultText = "config.boot.kernelPackages.netatop";
           description = ''
             Which package to use for netatop.
           '';
diff --git a/nixos/tests/atop.nix b/nixos/tests/atop.nix
index a2565e610ae1a..1f8b005041f0b 100644
--- a/nixos/tests/atop.nix
+++ b/nixos/tests/atop.nix
@@ -14,7 +14,10 @@ let assertions = rec {
   '';
   unit = name: state: ''
     with subtest("Unit ${name} should be ${state}"):
-        machine.require_unit_state("${name}", "${state}")
+        if "${state}" == "active":
+            machine.wait_for_unit("${name}")
+        else:
+            machine.require_unit_state("${name}", "${state}")
   '';
   version = ''
     import re
@@ -44,9 +47,19 @@ let assertions = rec {
     if present then
       unit "atop.service" "active"
       + ''
-        with subtest("atop.service should have written some data to /var/log/atop"):
-            files = int(machine.succeed("ls -1 /var/log/atop | wc -l"))
-            assert files > 0, "Expected at least 1 data file"
+        with subtest("atop.service should write some data to /var/log/atop"):
+
+            def has_data_files(last: bool) -> bool:
+                files = int(machine.succeed("ls -1 /var/log/atop | wc -l"))
+                if files == 0:
+                    machine.log("Did not find at least one 1 data file")
+                    if not last:
+                        machine.log("Will retry...")
+                    return False
+                return True
+
+            with machine.nested("Waiting for data files"):
+                retry(has_data_files)
       '' else unit "atop.service" "inactive";
   atopRotateTimer = present:
     unit "atop-rotate.timer" (if present then "active" else "inactive");
@@ -55,11 +68,21 @@ let assertions = rec {
       unit "atopacct.service" "active"
       + ''
         with subtest("atopacct.service should enable process accounting"):
-            machine.succeed("test -f /run/pacct_source")
+            machine.wait_until_succeeds("test -f /run/pacct_source")
 
         with subtest("atopacct.service should write data to /run/pacct_shadow.d"):
-            files = int(machine.succeed("ls -1 /run/pacct_shadow.d | wc -l"))
-            assert files >= 1, "Expected at least 1 pacct_shadow.d file"
+
+            def has_data_files(last: bool) -> bool:
+                files = int(machine.succeed("ls -1 /run/pacct_shadow.d | wc -l"))
+                if files == 0:
+                    machine.log("Did not find at least one 1 data file")
+                    if not last:
+                        machine.log("Will retry...")
+                    return False
+                return True
+
+            with machine.nested("Waiting for data files"):
+                retry(has_data_files)
       '' else unit "atopacct.service" "inactive";
   netatop = present:
     if present then