]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1638] wait for process to stop after kill
authorAndrei Pavel <andrei@isc.org>
Thu, 7 Jan 2021 17:38:52 +0000 (19:38 +0200)
committerAndrei Pavel <andrei@isc.org>
Fri, 22 Jan 2021 16:37:13 +0000 (18:37 +0200)
src/bin/admin/tests/memfile_tests.sh.in
src/lib/testutils/dhcp_test_lib.sh.in

index c68f3814f09c5118cf28ea70afd26888d6cd7f29..59bbcd3b90f3bc4193f63518cd4e7da5644079fd 100644 (file)
@@ -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
index c3f8e7cb21b3494a274708f2fdf43f7a9a9fb59c..a96d581fc9916293ce6feeae7fd8d3486aa0cd2d 100644 (file)
@@ -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.