From 2f870aa896dff06dc4cae9875a4f53831169d14c Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Tue, 1 Jun 2021 15:22:31 +0000 Subject: [PATCH] integration: Cleanup containerd on test teardown On Windows, we were only killing the keepalive process, and the containerd process would keep running. keepalive and containerd have the same PGID, so we can use that information to kill both of them. Signed-off-by: Claudiu Belu --- script/test/utils.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/script/test/utils.sh b/script/test/utils.sh index 6a40d324d..c72e34362 100755 --- a/script/test/utils.sh +++ b/script/test/utils.sh @@ -79,7 +79,7 @@ CONTAINERD_FLAGS+="--address ${TRIMMED_CONTAINERD_SOCK} \ --state ${CONTAINERD_STATE} \ --root ${CONTAINERD_ROOT}" -kill_containerd_cmd= +pid= # NOTE: We don't have the sudo command on Windows. sudo="" @@ -103,12 +103,6 @@ test_setup() { pid=$! set +m - if [ $IS_WINDOWS -eq 1 ]; then - kill_containerd_cmd="${sudo} kill ${pid}" - else - kill_containerd_cmd="${sudo} pkill -g $(ps -o pgid= -p ${pid})" - fi - # Wait for containerd to be running by using the containerd client ctr to check the version # of the containerd server. Wait an increasing amount of time after each of five attempts local -r crictl_path=$(which crictl) @@ -122,8 +116,14 @@ test_setup() { # test_teardown kills containerd. test_teardown() { - if [ -n "${kill_containerd_cmd}" ]; then - ${kill_containerd_cmd} + if [ -n "${pid}" ]; then + if [ $IS_WINDOWS -eq 1 ]; then + # NOTE(claudiub): The containerd process will have the same PGID as the keepalive process, + # so we can kill both of them by matching the PGID. + ${sudo} ps | awk "{if (\$3 == ${pid}) print \$1}" | xargs kill + else + ${sudo} pkill -g $(ps -o pgid= -p ${pid}) + fi fi }