Fix testing kill_all_servald_processes() function

dnaprotcol tests now always PASS
This commit is contained in:
Andrew Bettison 2012-06-22 14:18:05 +09:30
parent 3a6ea4ad75
commit 6af6d5ee7e

View File

@ -180,31 +180,47 @@ signal_all_servald_processes() {
echo "# Sent SIG$sig to servald process pid=$pid" echo "# Sent SIG$sig to servald process pid=$pid"
ret=0 ret=0
else else
error "# servald process pid=$pid not running -- SIG$sig not sent" echo "# servald process pid=$pid not running -- SIG$sig not sent"
fi fi
done done
return $ret return $ret
} }
# Utility function for tearing down DNA fixtures:
# - wait while any servald processes remain
# - return 0 if no processes are present
# - 1 if the timeout elapses first
wait_all_servald_processes() {
local timeout="${1:-1000000}"
sleep $timeout &
sleep_pid=$!
while get_servald_pids; do
kill -0 $sleep_pid 2>/dev/null || return 1
sleep 0.1
_tfw_echo -n .
done
kill -TERM $sleep_pid 2>/dev/null
return 0
}
# Utility function for tearing down DNA fixtures: # Utility function for tearing down DNA fixtures:
# - terminate all running servald processes, identified by name, by sending # - terminate all running servald processes, identified by name, by sending
# first SIGTERM then SIGHUP and finally SIGKILL # two SIGHUPs 100ms apart, then another SIGHUP after 2 seconds, finally
# - assert that no more servald processes are running # SIGKILL after 2 seconds
# - return 0 if no more processes are running, nonzero otherwise
kill_all_servald_processes() { kill_all_servald_processes() {
# PGS 20120621 - Made fast so that tests can be run quickly for delay in 0.1 2 2; do
# TODO: Make this better by checking that things really have died, and take signal_all_servald_processes HUP || return 0
# exactly the time required, rather than using fixed delays wait_all_servald_processes $delay && return 0
# if signal_all_servald_processes TERM; then done
# sleep 2 signal_all_servald_processes KILL || return 0
# if signal_all_servald_processes HUP; then return 1
# sleep 2
signal_all_servald_processes KILL
# fi
# fi
} }
# Utility function: # Utility function:
# - return the PIDs of all servald processes the current user is running # - return the PIDs of all servald processes the current user is running in the
# named array variable (if no name given, do not set any variable)
# - return 0 if there are any servald processes running, 1 if not
get_servald_pids() { get_servald_pids() {
local var="$1" local var="$1"
local servald_basename="${servald##*/}" local servald_basename="${servald##*/}"
@ -212,7 +228,8 @@ get_servald_pids() {
error "\$servald is not set" error "\$servald is not set"
return 1 return 1
fi fi
local pids=$(ps -u$UID | awk -v servald="$servald_basename" '$4 == servald {print $1}') local mypid=$$
local pids=$(ps -u$UID | awk -v mypid="$mypid" -v servald="$servald_basename" '$1 != mypid && $4 == servald {print $1}')
[ -n "$var" ] && eval "$var=($pids)" [ -n "$var" ] && eval "$var=($pids)"
[ -n "$pids" ] [ -n "$pids" ]
} }