diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-07-19 22:53:34 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-07-19 22:53:34 +0200 |
| commit | 4ee2db00225db217329b79294fc5a7e55a6ac808 (patch) | |
| tree | 821d7028dd69d145b2e64c10a1454c5abc7aed71 /tests/default.nix | |
| parent | tests/common/acme: Start all test machines concurrently (diff) | |
| download | nixos-server-4ee2db00225db217329b79294fc5a7e55a6ac808.zip | |
tests/default.nix: Work around a race-condition in the acme cert waiting
Diffstat (limited to '')
| -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) |
