From a406485aef4ca34279f69b4d00a04a78497efe07 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 27 May 2026 12:14:45 +0200 Subject: [PATCH] test/system: fix "stop container when healthcheck runs" flake This is a long standing flake but I see it again in the lima CI, the problem seems to happen when we stop the container before the background healthcheck fires. Signed-off-by: Paul Holzinger (cherry picked from commit 90ba6562d5d82f1dc649dd3f779d2a0f25362383) Signed-off-by: Paul Holzinger --- test/system/220-healthcheck.bats | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/system/220-healthcheck.bats b/test/system/220-healthcheck.bats index 7ad946c604..1add76646e 100644 --- a/test/system/220-healthcheck.bats +++ b/test/system/220-healthcheck.bats @@ -429,7 +429,7 @@ function _check_health_log { hcStatus=$PODMAN_TMPDIR/hcStatus run_podman run -d --name $ctr \ - --health-cmd "sleep 20; echo $msg" \ + --health-cmd "touch /tmp/abc; sleep 20; echo $msg" \ $IMAGE /home/podman/pause timeout --foreground -v --kill=10 60 \ @@ -439,6 +439,24 @@ function _check_health_log { run_podman inspect $ctr --format "{{.State.Status}}" assert "$output" == "running" "Container is running" + ### Flake, sometimes it is possible that the background healthcheck runs so slow that + # it starts after the podman stop below and then fails with + # "can only create exec sessions on running containers: container state improper". + # To fix this we wait for a file th healthcheck creates right away to know it is running. + timeout=5 + while :; do + run_podman '?' exec $ctr cat /tmp/abc + if [[ "$status" -eq 0 ]]; then + break + fi + + timeout=$((timeout - 1)) + if [[ $timeout -eq 0 ]]; then + die "timed out waiting for healthcheck to run and create test file" + fi + sleep 1 + done + run_podman stop $ctr # Wait for background healthcheck to finish and make sure the exit status is 1