Changeset 232fb60 in mod_gnutls for test/runtests


Ignore:
Timestamp:
Mar 31, 2015, 7:03:16 PM (5 years ago)
Author:
Thomas Klute <thomas2.klute@…>
Branches:
debian/master, debian/stretch-backports, jessie-backports, master, upstream
Children:
1b57c56
Parents:
a213967
Message:

runtests: Stop background sleep after gnutls-cli is done

The PID of the background sleep used to wait for an HTTP response is now
stored in a temporary file, so the sleep process can be stopped when it
is no longer needed. This avoids cluttering the system with sleep
processes and thus allows a more than generous timeout, which should be
useful for slow build systems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/runtests

    ra213967 r232fb60  
    4444function diff_output_filter_headers()
    4545{
    46     expected="$1"
    47     actual="$2"
     46    local expected="$1"
     47    local actual="$2"
    4848    diff $3 -u "${expected}" <( cat "${actual}" | \
    4949        grep -v -P '^Date:\s.*GMT\s?$' | \
    5050        grep -v -P '^Server:\sApache'  | \
    5151        tail -n "$(wc -l < ${expected})" )
     52}
     53
     54# Run a command, storing its PID in the given file
     55# Usage: run_with_pidfile PIDFILE COMMAND [ARGS]
     56function run_with_pidfile()
     57{
     58    local pidfile=$1
     59    local cmd=$2
     60    shift 2
     61    echo $BASHPID >${pidfile}
     62    exec ${cmd} $*
     63}
     64
     65# Kills the process with the PID contained in a given file, then
     66# deletes the file.
     67# Usage: kill_by_pidfile PIDFILE
     68function kill_by_pidfile()
     69{
     70    local pidfile="${1}"
     71    # In some testcases with expected failure, gnutls-cli sometimes
     72    # failed before the subshell in front of the pipe (see gnutls-cli
     73    # call below) got so far as to write the PID, much less exec
     74    # sleep. So we need to check if there actually is anything to
     75    # kill.
     76    if [ -n "${pidfile}" ]; then
     77        local pid=$(cat "${pidfile}")
     78        if [ -n "${pid}" ] && ps -p "${pid}"; then
     79            kill "${pid}"
     80        fi
     81        rm "${pidfile}"
     82    fi
    5283}
    5384
     
    5990        diff_output_filter_headers "output" "$output" || true
    6091    fi
     92
     93    if [ -n "${sleep_pidfile}" ]; then
     94        kill_by_pidfile "${sleep_pidfile}"
     95    fi
     96
    6197    printf "\nApache error logs:\n"
    6298    tail "../../logs/${TEST_NAME}.error.log"
     99
    63100    if [ -n "${USE_MSVA}" ]; then
    64101        stop_msva
     
    110147    fi
    111148
     149    # PID file for sleep command (explanation below)
     150    sleep_pidfile="$(mktemp mod_gnutls_test-XXXXXX.pid)"
     151
    112152    # The sleep call keeps the pipe from the subshell to gnutls-cli
    113153    # open. Without it gnutls-cli would terminate as soon as sed is
    114154    # done, and not wait for a response from the server, leading to
    115155    # failing tests. Sending sleep to the background allows the test
    116     # case to proceed instead of waiting for it to return, but has the
    117     # disadvantage of leaving the sleep process dangling until it
    118     # eventually times out. Still preferable to a fixed delay.
     156    # case to proceed instead of waiting for it to return. The sleep
     157    # process is stopped after gnutls-cli terminates.
    119158    if (sed "s/__HOSTNAME__/${TEST_HOST}/" <./input && \
    120         sleep "${TEST_QUERY_DELAY}" &) | \
     159        run_with_pidfile "${sleep_pidfile}" sleep "${TEST_QUERY_DELAY}" &) | \
    121160        gnutls-cli -p "${TEST_PORT}" $(cat ./gnutls-cli.args) "${TEST_HOST}" \
    122161        >"$output";
     
    132171        fi
    133172    fi
     173
     174    kill_by_pidfile "${sleep_pidfile}"
    134175
    135176    if [ -e output ] ; then
Note: See TracChangeset for help on using the changeset viewer.