diff options
Diffstat (limited to 'tests/default.nix')
| -rw-r--r-- | tests/default.nix | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/tests/default.nix b/tests/default.nix index 48fa9ec..9bab516 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -136,21 +136,37 @@ return status == 0 wasAlive: bool + deadCounter: int def run_and_wait(host, unit: str): global wasAlive + global deadCounter + wasAlive = False + deadCounter = 0 + def wait_state(_last_try: bool) -> bool: global wasAlive + global deadCounter state = host.get_unit_property(unit, "SubState") - if state == "failed": - assert False, f'Unit "{unit}" reached state "{state}"' + host.log(f"(waiting) {unit} -> {state}") - if state == "start" or state == "active" or state == "running": + match state: + case "failed": + assert False, f'Unit "{unit}" reached state "{state}"' + case "start" | "active" | "running": wasAlive = True + case "dead": + if wasAlive: + return True + else: + if deadCounter >= 5: + return True - host.log(f"(waiting) {unit} -> {state}") - return wasAlive and state == "dead" + deadCounter = deadCounter + 1 + return False + + return False with host.nested(f"Waiting for unit {unit}"): retry(wait_state) |
