summaryrefslogtreecommitdiff
path: root/test/system
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2021-07-29 11:54:50 -0600
committerEd Santiago <santiago@redhat.com>2021-07-29 11:57:51 -0600
commitd59391c04770a624859662df27e3c1f1c5178892 (patch)
treeadbbd2dd32a4dc85483b5f9a57ab75684790463e /test/system
parentf17b810279fd04c3d574e8d3dcc1878d50083a68 (diff)
downloadpodman-d59391c04770a624859662df27e3c1f1c5178892.tar.gz
podman-d59391c04770a624859662df27e3c1f1c5178892.tar.bz2
podman-d59391c04770a624859662df27e3c1f1c5178892.zip
system tests: fix race in stop test
In the unlock/timeout test, on slow systems, 'podman ps' could catch the container before the just-backgrounded 'podman stop' sends the signal. Wait for signal ack from container before we inspect it. Also: If I understand the test correctly, it wasn't actually checking that 'ps' could grab the lock while the container was exiting. Add a check. Signed-off-by: Ed Santiago <santiago@redhat.com>
Diffstat (limited to 'test/system')
-rw-r--r--test/system/050-stop.bats31
1 files changed, 29 insertions, 2 deletions
diff --git a/test/system/050-stop.bats b/test/system/050-stop.bats
index 2ed791429..d809507a5 100644
--- a/test/system/050-stop.bats
+++ b/test/system/050-stop.bats
@@ -119,11 +119,31 @@ load helpers
# the container's status.
run_podman run --name stopme -d $IMAGE sh -c \
- "trap 'echo Received SIGTERM, ignoring' SIGTERM; echo READY; while :; do sleep 1; done"
+ "trap 'echo Received SIGTERM, ignoring' SIGTERM; echo READY; while :; do sleep 0.2; done"
- # Stop the container in the background
+ wait_for_ready stopme
+
+ local t0=$SECONDS
+ # Stop the container, but do so in the background so we can inspect
+ # the container status while it's stopping. Use $PODMAN because we
+ # don't want the overhead and error checks of run_podman.
$PODMAN stop -t 20 stopme &
+ # Wait for container to acknowledge the signal. We can't use wait_for_output
+ # because that aborts if .State.Running != true
+ local timeout=5
+ while [[ $timeout -gt 0 ]]; do
+ run_podman logs stopme
+ if [[ "$output" =~ "Received SIGTERM, ignoring" ]]; then
+ break
+ fi
+ timeout=$((timeout - 1))
+ if [[ $timeout -eq 0 ]]; then
+ die "Timed out waiting for container to receive SIGERM"
+ fi
+ sleep 0.5
+ done
+
# Other commands can acquire the lock
run_podman ps -a
@@ -131,6 +151,13 @@ load helpers
run_podman inspect --format '{{.State.Status}}' stopme
is "$output" "stopping" "Status of container should be 'stopping'"
+ # Time check: make sure we were able to run 'ps' before the container
+ # exited. If this takes too long, it means ps had to wait for lock.
+ local delta_t=$(( $SECONDS - t0 ))
+ if [[ $delta_t -gt 5 ]]; then
+ die "Operations took too long ($delta_t seconds)"
+ fi
+
run_podman kill stopme
run_podman wait stopme