Skip to content

Commit

Permalink
chore(linux): Improve process check
Browse files Browse the repository at this point in the history
  • Loading branch information
ermshiperete committed Oct 10, 2023
1 parent b0e0846 commit fec84e9
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions linux/ibus-keyman/tests/scripts/test-helper.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,9 @@ function exit_on_package_build() {
fi
}

function check_processes_running() {
local DISPLAY_SERVER ENV_FILE CLEANUP_FILE PID_FILE LINE PID MISSING MISSING_PROCS TEST_NAME
DISPLAY_SERVER=$1
ENV_FILE=$2
CLEANUP_FILE=$3
PID_FILE=$4
TEST_NAME=$5
MISSING=false
function _get_missing_processes() {
local PID_FILE MISSING_PROCS PID LINE
PID_FILE=$1
MISSING_PROCS=""

while read -r LINE; do
Expand All @@ -339,13 +334,22 @@ function check_processes_running() {
fi
PID=$(echo "$LINE" | cut -d' ' -f1)
if ! ps --no-headers --pid="$PID" > /dev/null; then
MISSING=true
MISSING_PROCS="${MISSING_PROCS} $(echo "$LINE" | cut -d' ' -f2)"
break
fi
done < "${PID_FILE}"
}

function check_processes_running() {
local DISPLAY_SERVER ENV_FILE CLEANUP_FILE PID_FILE MISSING_PROCS TEST_NAME
DISPLAY_SERVER=$1
ENV_FILE=$2
CLEANUP_FILE=$3
PID_FILE=$4
TEST_NAME=$5
MISSING_PROCS=$(_get_missing_processes "$PID_FILE")

if $MISSING; then
if [ "$MISSING_PROCS" != "" ]; then
echo "# Some background processes no longer running. Restarting..."
{ echo "Some background processes no longer running (running ${TEST_NAME}):" ; \
echo "$MISSING_PROCS" ; \
Expand All @@ -354,4 +358,9 @@ function check_processes_running() {
cleanup "${CLEANUP_FILE}" > /dev/null 2>&1
setup "${DISPLAY_SERVER}" "${ENV_FILE}" "${CLEANUP_FILE}" "${PID_FILE}" > /dev/null 2>&1
fi

if [ "$(_get_missing_processes "$PID_FILE")" != "" ]; then
echo "# WARNING: Expected background processes are still missing after restart: ${MISSING_PROCS}"
echo "# Maybe an old process is still running?"
fi
}

0 comments on commit fec84e9

Please sign in to comment.