@@ -139,20 +139,23 @@ Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\"
139
139
run_podman 1 healthcheck run $ctr
140
140
is " $output " " unhealthy" " output from 'podman healthcheck run' (policy: $policy )"
141
141
142
- run_podman inspect $ctr --format " {{.State.Status}} {{.Config.HealthcheckOnFailureAction}}"
143
- if [[ $policy == " restart" ]]; then
144
- # Container has been restarted and health check works again
145
- is " $output " " running $policy " " container has been restarted"
146
- run_podman container inspect $ctr --format " {{.State.Healthcheck.FailingStreak}}"
147
- is " $output " " 0" " Failing streak of restarted container should be 0 again"
148
- run_podman healthcheck run $ctr
142
+ if [[ $policy == " restart" ]]; then
143
+ # Make sure the container transitions back to running
144
+ run_podman wait --condition=running $ctr
145
+ run_podman inspect $ctr --format " {{.RestartCount}}"
146
+ assert " ${# lines[@]} " ! = 0 " Container has been restarted at least once"
147
+ run_podman container inspect $ctr --format " {{.State.Healthcheck.FailingStreak}}"
148
+ is " $output " " 0" " Failing streak of restarted container should be 0 again"
149
+ run_podman healthcheck run $ctr
149
150
elif [[ $policy == " none" ]]; then
151
+ run_podman inspect $ctr --format " {{.State.Status}} {{.Config.HealthcheckOnFailureAction}}"
150
152
# Container is still running and health check still broken
151
153
is " $output " " running $policy " " container continued running"
152
154
run_podman 1 healthcheck run $ctr
153
155
is " $output " " unhealthy" " output from 'podman healthcheck run' (policy: $policy )"
154
- else
155
- # kill and stop yield the container into a non-running state
156
+ else
157
+ run_podman inspect $ctr --format " {{.State.Status}} {{.Config.HealthcheckOnFailureAction}}"
158
+ # kill and stop yield the container into a non-running state
156
159
is " $output " " .* $policy " " container was stopped/killed (policy: $policy )"
157
160
assert " $output " ! = " running $policy "
158
161
# also make sure that it's not stuck in the stopping state
@@ -164,4 +167,39 @@ Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\"
164
167
done
165
168
}
166
169
170
+ @test " podman healthcheck --health-on-failure with interval" {
171
+ ctr=" healthcheck_c"
172
+
173
+ for policy in stop kill restart ; do
174
+ t0=$( date --iso-8601=seconds)
175
+ run_podman run -d --name $ctr \
176
+ --health-cmd /bin/false \
177
+ --health-retries=1 \
178
+ --health-on-failure=$policy \
179
+ --health-interval=1s \
180
+ $IMAGE top
181
+
182
+ if [[ $policy == " restart" ]]; then
183
+ # Sleeping for 2 seconds makes the test much faster than using
184
+ # podman-wait which would compete with the container getting
185
+ # restarted.
186
+ sleep 2
187
+ # Make sure the container transitions back to running
188
+ run_podman wait --condition=running $ctr
189
+ run_podman inspect $ctr --format " {{.RestartCount}}"
190
+ assert " ${# lines[@]} " ! = 0 " Container has been restarted at least once"
191
+ else
192
+ # kill and stop yield the container into a non-running state
193
+ run_podman wait $ctr
194
+ run_podman inspect $ctr --format " {{.State.Status}} {{.Config.HealthcheckOnFailureAction}}"
195
+ is " $output " " .* $policy " " container was stopped/killed (policy: $policy )"
196
+ assert " $output " ! = " running $policy "
197
+ # also make sure that it's not stuck in the stopping state
198
+ assert " $output " ! = " stopping $policy "
199
+ fi
200
+
201
+ run_podman rm -f -t0 $ctr
202
+ done
203
+ }
204
+
167
205
# vim: filetype=sh
0 commit comments