mirror of
https://github.com/containers/podman.git
synced 2025-12-05 04:40:47 +08:00
Merge pull request #16607 from vrothberg/BZ-2144754
container restart: clean up healthcheck state
This commit is contained in:
@@ -76,6 +76,34 @@ Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\"
|
||||
run_podman rmi healthcheck_i
|
||||
}
|
||||
|
||||
@test "podman healthcheck - restart cleans up old state" {
|
||||
ctr="healthcheck_c"
|
||||
img="healthcheck_i"
|
||||
|
||||
_build_health_check_image $img cleanfile
|
||||
run_podman run -d --name $ctr \
|
||||
--health-cmd /healthcheck \
|
||||
--health-retries=2 \
|
||||
--health-interval=disable \
|
||||
$img
|
||||
|
||||
run_podman container inspect $ctr --format "{{.State.Healthcheck.FailingStreak}}"
|
||||
is "$output" "0" "Failing streak of fresh container should be 0"
|
||||
|
||||
# Get the healthcheck to fail
|
||||
run_podman exec $ctr touch /uh-oh
|
||||
run_podman 1 healthcheck run $ctr
|
||||
is "$output" "unhealthy" "output from 'podman healthcheck run'"
|
||||
run_podman container inspect $ctr --format "{{.State.Healthcheck.FailingStreak}}"
|
||||
is "$output" "1" "Failing streak after one failed healthcheck should be 1"
|
||||
|
||||
run_podman container restart $ctr
|
||||
run_podman container inspect $ctr --format "{{.State.Healthcheck.FailingStreak}}"
|
||||
is "$output" "0" "Failing streak of restarted container should be 0 again"
|
||||
|
||||
run_podman rm -f -t0 $ctr
|
||||
}
|
||||
|
||||
@test "podman healthcheck --health-on-failure" {
|
||||
run_podman 125 create --health-on-failure=kill $IMAGE
|
||||
is "$output" "Error: cannot set on-failure action to kill without a health check"
|
||||
@@ -114,6 +142,8 @@ Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\"
|
||||
if [[ $policy == "restart" ]];then
|
||||
# Container has been restarted and health check works again
|
||||
is "$output" "running $policy" "container has been restarted"
|
||||
run_podman container inspect $ctr --format "{{.State.Healthcheck.FailingStreak}}"
|
||||
is "$output" "0" "Failing streak of restarted container should be 0 again"
|
||||
run_podman healthcheck run $ctr
|
||||
elif [[ $policy == "none" ]];then
|
||||
# Container is still running and health check still broken
|
||||
|
||||
Reference in New Issue
Block a user