From e216457eea3e9074bd064685ffa78eeea9700883 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sun, 19 Apr 2020 21:28:15 -0700 Subject: [PATCH] tests/checkpoint.bats: simplify status checks Introduce a special case for `testcontainer` to test for container that is not present (checkpointed), use it. Fix one place where testcontainer was not used. Signed-off-by: Kir Kolyshkin --- tests/integration/checkpoint.bats | 16 +++++----------- tests/integration/helpers.bash | 4 ++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/integration/checkpoint.bats b/tests/integration/checkpoint.bats index 4c5c6a038..0e9484068 100644 --- a/tests/integration/checkpoint.bats +++ b/tests/integration/checkpoint.bats @@ -33,8 +33,7 @@ function teardown() { [ "$status" -eq 0 ] # after checkpoint busybox is no longer running - runc state test_busybox - [ "$status" -ne 0 ] + testcontainer test_busybox checkpointed # restore from checkpoint runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket $CONSOLE_SOCKET test_busybox @@ -87,9 +86,7 @@ function teardown() { [ "$status" -eq 0 ] # busybox should still be running - runc state test_busybox - [ "$status" -eq 0 ] - [[ "${output}" == *"running"* ]] + testcontainer test_busybox running # checkpoint the running container mkdir image-dir @@ -99,8 +96,7 @@ function teardown() { [ "$status" -eq 0 ] # after checkpoint busybox is no longer running - runc state test_busybox - [ "$status" -ne 0 ] + testcontainer test_busybox checkpointed # restore from checkpoint __runc --criu "$CRIU" restore -d --work-path ./work-dir --image-path ./image-dir test_busybox <&60 >&51 2>&51 @@ -271,8 +267,7 @@ function teardown() { [ "$status" -eq 0 ] # after checkpoint busybox is no longer running - runc state test_busybox - [ "$status" -ne 0 ] + testcontainer test_busybox checkpointed # restore from checkpoint; this should restore the container into the existing network namespace runc --criu "$CRIU" restore -d --work-path ./work-dir --console-socket $CONSOLE_SOCKET test_busybox @@ -327,8 +322,7 @@ function teardown() { test -f ./work-dir/$tmplog2 # after checkpoint busybox is no longer running - runc state test_busybox - [ "$status" -ne 0 ] + testcontainer test_busybox checkpointed test -f ./work-dir/$tmplog2 && unlink ./work-dir/$tmplog2 # restore from checkpoint diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index de8be4ba5..df0795782 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -310,6 +310,10 @@ function wait_for_container_inroot() { function testcontainer() { # test state of container runc state $1 + if [ $2 == "checkpointed" ]; then + [ "$status" -eq 1 ] + return + fi [ "$status" -eq 0 ] [[ "${output}" == *"$2"* ]] }