From b07c19eb5f91503daa9bbf9db385843aa1cae16e Mon Sep 17 00:00:00 2001 From: Gabriela Cervantes Date: Thu, 10 Aug 2023 20:12:22 +0000 Subject: [PATCH] metrics: Add check containers are running function This PR adds the check containers are running function the common metrics script. Signed-off-by: Gabriela Cervantes (cherry picked from commit 833cf7a684658fcb20ddcf5e80bcb75aa92d03c5) --- tests/metrics/lib/common.bash | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/metrics/lib/common.bash b/tests/metrics/lib/common.bash index a715ea035d..327379a517 100755 --- a/tests/metrics/lib/common.bash +++ b/tests/metrics/lib/common.bash @@ -397,3 +397,21 @@ function check_containers_are_up() { [ "${i}" == "${TIMEOUT}" ] && return 1 done } + +function check_containers_are_running() { + local NUM_CONTAINERS="$1" + [[ -z "${NUM_CONTAINERS}" ]] && die "Number of containers is missing" + + # Check that the requested number of containers are running + local timeout_launch="10" + check_containers_are_up "${NUM_CONTAINERS}" & pid=$! + (sleep "${timeout_launch}" && kill -HUP "${pid}") 2>/dev/null & pid_tout=$! + + if wait "${pid}" 2>/dev/null; then + pkill -HUP -P "${pid_tout}" + wait "${pid_tout}" + else + warn "Time out exceeded" + return 1 + fi +}