summaryrefslogtreecommitdiff
path: root/test/system/050-stop.bats
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2019-02-20 13:19:20 -0700
committerEd Santiago <santiago@redhat.com>2019-03-07 13:09:54 -0700
commit681eae9bcc856f8dad107765a97c29d0fe093d4a (patch)
treea8224181c5b01ebfece7e309117b9bc1d4e5a9a0 /test/system/050-stop.bats
parent1b253cf73a360557196213684cec63b37407ed7c (diff)
downloadpodman-681eae9bcc856f8dad107765a97c29d0fe093d4a.tar.gz
podman-681eae9bcc856f8dad107765a97c29d0fe093d4a.tar.bz2
podman-681eae9bcc856f8dad107765a97c29d0fe093d4a.zip
new system tests under BATS
Initial attempt at writing a framework for podman system tests. The idea is to define a useful set of primitives that will make it easy to write actual tests and to interpret results of failing ones. This is a proof-of-concept right now; only a small number of tests, by no means comprehensive. I am requesting review in order to find showstopper problems: reasons why this approach cannot work. Should there be none, we can work toward running these as gating tests for Fedora and RHEL8. Signed-off-by: Ed Santiago <santiago@redhat.com>
Diffstat (limited to 'test/system/050-stop.bats')
-rw-r--r--test/system/050-stop.bats65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/system/050-stop.bats b/test/system/050-stop.bats
new file mode 100644
index 000000000..d04e22606
--- /dev/null
+++ b/test/system/050-stop.bats
@@ -0,0 +1,65 @@
+#!/usr/bin/env bats
+
+load helpers
+
+# Very simple test
+@test "podman stop - basic test" {
+ run_podman run -d $PODMAN_TEST_IMAGE_FQN sleep 60
+ cid="$output"
+
+ # Run 'stop'. Time how long it takes.
+ t0=$SECONDS
+ run_podman stop $cid
+ t1=$SECONDS
+
+ # Confirm that container is stopped
+ run_podman inspect --format '{{.State.Status}} {{.State.ExitCode}}' $cid
+ is "$output" "exited \+137" "Status and exit code of stopped container"
+
+ # The initial SIGTERM is ignored, so this operation should take
+ # exactly 10 seconds. Give it some leeway.
+ delta_t=$(( $t1 - $t0 ))
+ [ $delta_t -gt 8 ] ||\
+ die "podman stop: ran too quickly! ($delta_t seconds; expected >= 10)"
+ [ $delta_t -le 14 ] ||\
+ die "podman stop: took too long ($delta_t seconds; expected ~10)"
+
+ run_podman rm $cid
+}
+
+
+# Test fallback
+
+
+# Regression test for #2472
+@test "podman stop - can trap signal" {
+ # Because the --time and --timeout options can be wonky, try three
+ # different variations of this test.
+ for t_opt in '' '--time=5' '--timeout=5'; do
+ # Run a simple container that logs output on SIGTERM
+ run_podman run -d $PODMAN_TEST_IMAGE_FQN sh -c \
+ "trap 'echo Received SIGTERM, finishing; exit' SIGTERM; echo READY; while :; do sleep 1; done"
+ cid="$output"
+ wait_for_ready $cid
+
+ # Run 'stop' against it...
+ t0=$SECONDS
+ run_podman stop $t_opt $cid
+ t1=$SECONDS
+
+ # ...the container should trap the signal, log it, and exit.
+ run_podman logs $cid
+ is "$output" ".*READY.*Received SIGTERM, finishing" "podman stop $t_opt"
+
+ # Exit code should be 0, because container did its own exit
+ run_podman inspect --format '{{.State.ExitCode}}' $cid
+ is "$output" "0" "Exit code of stopped container"
+
+ # The 'stop' command should return almost instantaneously
+ delta_t=$(( $t1 - $t0 ))
+ [ $delta_t -le 2 ] ||\
+ die "podman stop: took too long ($delta_t seconds; expected <= 2)"
+
+ run_podman rm $cid
+ done
+}