From: Andrei Pavel Date: Thu, 7 Jan 2021 17:38:52 +0000 (+0200) Subject: [#1638] wait for process to stop after kill X-Git-Tag: Kea-1.9.4~53 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c49aa5db63695584912867ecbdf64bc1455d5737;p=thirdparty%2Fkea.git [#1638] wait for process to stop after kill --- diff --git a/src/bin/admin/tests/memfile_tests.sh.in b/src/bin/admin/tests/memfile_tests.sh.in index c68f3814f0..59bbcd3b90 100644 --- a/src/bin/admin/tests/memfile_tests.sh.in +++ b/src/bin/admin/tests/memfile_tests.sh.in @@ -136,7 +136,7 @@ memfile_init_test() { clean_exit 1 fi kill "${PID}" - if ! wait_for_process_to_die "${PID}"; then + if ! wait_for_process_to_stop "${PID}"; then clean_up clean_exit 2 fi diff --git a/src/lib/testutils/dhcp_test_lib.sh.in b/src/lib/testutils/dhcp_test_lib.sh.in index c3f8e7cb21..a96d581fc9 100644 --- a/src/lib/testutils/dhcp_test_lib.sh.in +++ b/src/lib/testutils/dhcp_test_lib.sh.in @@ -458,8 +458,8 @@ get_process_name() { # Wait for file to be created. wait_for_file() { local file=${1} - timeout='4' # seconds - deadline=$(($(date +%s) + timeout)) + local timeout='4' # seconds + local deadline=$(($(date +%s) + timeout)) while ! test -f "${file}"; do if test "${deadline}" -lt "$(date +%s)"; then # Time is up. @@ -472,17 +472,17 @@ wait_for_file() { } # Wait for process identified by PID to die. -wait_for_process_to_die() { +wait_for_process_to_stop() { local pid=${1} - timeout='4' # seconds - deadline=$(($(date +%s) + timeout)) + local timeout='4' # seconds + local deadline=$(($(date +%s) + timeout)) while ps "${pid}" >/dev/null; do if test "${deadline}" -lt "$(date +%s)"; then # Time is up. - printf 'ERROR: %s does not want to die.\n' "$(get_process_name "${pid}")" >&2 + printf 'ERROR: %s is not stopping.\n' "$(get_process_name "${pid}")" >&2 return 1 fi - printf 'Waiting for %s to die...\n' "$(get_process_name "${pid}")" + printf 'Waiting for %s to stop...\n' "$(get_process_name "${pid}")" sleep 1 done } @@ -501,9 +501,10 @@ wait_for_process_to_die() { kill_processes_by_name() { local proc_name=${1} # Process name if [ -z "${proc_name}" ]; then - test_lib_error "get_pids requires process name" + test_lib_error "kill_processes_by_name requires process name" clean_exit 1 fi + # Obtain PIDs of running processes. local pids pids=$(pgrep "${proc_name}" || true) @@ -512,6 +513,12 @@ kill_processes_by_name() { printf 'Shutting down Kea process %s with PID %d...\n' "${proc_name}" "${pid}" kill -9 "${pid}" || true done + + # Wait for all processes to stop. + for pid in ${pids}; do + printf 'Waiting for Kea process %s with PID %d to stop...\n' "${proc_name}" "${pid}" + wait_for_process_to_stop "${pid}" + done } # Returns the number of occurrences of the Kea log message in the log file.