Fix healthcheck flake by capturing time before systemctl checks

After _check_health "First failure" returns with FailingStreak=2, the
3rd failure fires during the subsequent systemctl checks (~1s interval),
emitting the "unhealthy" event before current_time was captured. Move
current_time before those checks so --since doesn't miss the event.

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
This commit is contained in:
Jan Rodák 2026-06-04 16:11:54 +02:00
parent d18ed46101
commit 81fceb48d2
No known key found for this signature in database
GPG key ID: D458A9B20435C2BF

View file

@ -96,6 +96,10 @@ Log[-1].ExitCode | 1
Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\\\n\"
" "$current_time" "healthy"
# Capture time before systemctl checks so we don't miss the "unhealthy"
# event that may fire during those checks (health-interval is only 1s).
current_time=$(date --iso-8601=ns)
# Check that we now we do have valid podman units with this
# name so that the leak check below does not turn into a NOP without noticing.
run -0 systemctl list-units
@ -110,7 +114,6 @@ Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\\\n\"
run -0 systemctl show --all "$cid-*.service"
assert "$output" =~ "StartLimitIntervalUSec=0" "The hc service has the right interval set"
current_time=$(date --iso-8601=ns)
# After three successive failures, container should no longer be healthy
_check_health $ctrname "Four or more failures" "
Status | \"unhealthy\"