@@ -14,7 +14,10 @@ let assertions = rec {
1414 '';
1515 unit = name: state: ''
1616 with subtest("Unit ${name} should be ${state}"):
17− machine.require_unit_state("${name}", "${state}")
17+ if "${state}" == "active":
18+ machine.wait_for_unit("${name}")
19+ else:
20+ machine.require_unit_state("${name}", "${state}")
1821 '';
1922 version = ''
2023 import re
@@ -44,9 +47,19 @@ let assertions = rec {
4447 if present then
4548 unit "atop.service" "active"
4649 + ''
47− with subtest("atop.service should have written some data to /var/log/atop"):
48− files = int(machine.succeed("ls -1 /var/log/atop | wc -l"))
49− assert files > 0, "Expected at least 1 data file"
50+ with subtest("atop.service should write some data to /var/log/atop"):
51+
52+ def has_data_files(last: bool) -> bool:
53+ files = int(machine.succeed("ls -1 /var/log/atop | wc -l"))
54+ if files == 0:
55+ machine.log("Did not find at least one 1 data file")
56+ if not last:
57+ machine.log("Will retry...")
58+ return False
59+ return True
60+
61+ with machine.nested("Waiting for data files"):
62+ retry(has_data_files)
5063 '' else unit "atop.service" "inactive";
5164 atopRotateTimer = present:
5265 unit "atop-rotate.timer" (if present then "active" else "inactive");
@@ -55,11 +68,21 @@ let assertions = rec {
5568 unit "atopacct.service" "active"
5669 + ''
5770 with subtest("atopacct.service should enable process accounting"):
58− machine.succeed("test -f /run/pacct_source")
71+ machine.wait_until_succeeds("test -f /run/pacct_source")
5972
6073 with subtest("atopacct.service should write data to /run/pacct_shadow.d"):
61− files = int(machine.succeed("ls -1 /run/pacct_shadow.d | wc -l"))
62− assert files >= 1, "Expected at least 1 pacct_shadow.d file"
74+
75+ def has_data_files(last: bool) -> bool:
76+ files = int(machine.succeed("ls -1 /run/pacct_shadow.d | wc -l"))
77+ if files == 0:
78+ machine.log("Did not find at least one 1 data file")
79+ if not last:
80+ machine.log("Will retry...")
81+ return False
82+ return True
83+
84+ with machine.nested("Waiting for data files"):
85+ retry(has_data_files)
6386 '' else unit "atopacct.service" "inactive";
6487 netatop = present:
6588 if present then