iSulad/0039-CI-add-testcase-for-unless-stopped-restart-policy.patch

80 lines
2.3 KiB
Diff
Raw Normal View History

From 6d2ce70731b36c8e2942571dca71149c26474d25 Mon Sep 17 00:00:00 2001
From: Li Feng <lifeng2221dd1@zoho.com.cn>
Date: Tue, 23 Feb 2021 09:13:28 +0800
Subject: [PATCH 39/53] CI: add testcase for unless-stopped restart policy
Signed-off-by: Li Feng <lifeng2221dd1@zoho.com.cn>
---
.../container_cases/restartpolicy.sh | 48 +++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/CI/test_cases/container_cases/restartpolicy.sh b/CI/test_cases/container_cases/restartpolicy.sh
index be0140e7..bb7ada39 100755
--- a/CI/test_cases/container_cases/restartpolicy.sh
+++ b/CI/test_cases/container_cases/restartpolicy.sh
@@ -41,6 +41,52 @@ function do_test_on_failure()
fn_check_eq "$?" "0" "rm failed"
}
+function do_test_unless_stopped()
+{
+ containername=test_rp_unless_stopped
+ isula run --name $containername -td --restart unless-stopped busybox /bin/sh -c "exit 2"
+ fn_check_eq "$?" "0" "run failed"
+
+ sleep 8
+ count=`isula inspect --format='{{json .RestartCount}}' $containername`
+ if [[ $count == "0" ]];then
+ echo "expect not 0 but get $count"
+ TC_RET_T=$(($TC_RET_T+1))
+ fi
+
+ isula stop $containername
+ testcontainer $containername exited
+
+ isula rm $containername
+ fn_check_eq "$?" "0" "rm failed"
+}
+
+function do_test_unless_stopped_kill()
+{
+ containername=test_rp_unless_stopped
+ isula run --name $containername -td --restart unless-stopped busybox /bin/sh
+ fn_check_eq "$?" "0" "run failed"
+
+ cpid=`isula inspect -f '{{json .State.Pid}}' $containername`
+ kill -9 $cpid
+ sleep 8
+ testcontainer $containername running
+
+ isula stop $containername
+ fn_check_eq "$?" "0" "stop failed"
+ testcontainer $containername exited
+
+ isula restart $containername
+ testcontainer $containername running
+
+ isula kill $containername
+ fn_check_eq "$?" "0" "stop failed"
+ testcontainer $containername exited
+
+ isula rm $containername
+ fn_check_eq "$?" "0" "rm failed"
+}
+
function do_test_always_cancel()
{
containername=test_rp_always_cancel
@@ -64,6 +110,8 @@ function do_test_t()
{
do_test_on_failure
do_test_always_cancel
+ do_test_unless_stopped
+ do_test_unless_stopped_kill
return $TC_RET_T
}
--
2.25.1