Changeset 4fb510d in mod_gnutls


Ignore:
Timestamp:
Mar 5, 2017, 11:55:51 AM (6 years ago)
Author:
Thomas Klute <thomas2.klute@…>
Branches:
asyncio, debian/master, debian/stretch-backports, main, master, proxy-ticket, upstream
Children:
339a49d
Parents:
5f3222b
Message:

Test suite: Add generic function to wait for a command to succeed

The command is retried with a configurable wait time until it
succeeds, or a timeout expires. This is intended to wait for a service
to become ready, e.g. the OCSP responder or MSVA service used in
tests.

The MSVA and OCSP responder availability tests are modified to use the
new function.

Location:
test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • test/Makefile.am

    r5f3222b r4fb510d  
    209209endif
    210210# maximum time to wait for MSVA startup (milliseconds)
    211 TEST_MSVA_MAX_WAIT ?= 10000
     211TEST_SERVICE_MAX_WAIT ?= 10000
    212212# wait loop time for MSVA startup (milliseconds)
    213 TEST_MSVA_WAIT ?= 400
     213TEST_SERVICE_WAIT ?= 400
    214214
    215215AM_TESTS_ENVIRONMENT = export APACHE2=@APACHE2@; \
     
    219219        export TEST_PORT="$(TEST_PORT)"; \
    220220        export MSVA_PORT="$(MSVA_PORT)"; \
    221         export TEST_MSVA_MAX_WAIT="$(TEST_MSVA_MAX_WAIT)"; \
    222         export TEST_MSVA_WAIT="$(TEST_MSVA_WAIT)"; \
     221        export TEST_SERVICE_MAX_WAIT="$(TEST_SERVICE_MAX_WAIT)"; \
     222        export TEST_SERVICE_WAIT="$(TEST_SERVICE_WAIT)"; \
    223223        export TEST_QUERY_TIMEOUT="@TEST_QUERY_TIMEOUT@"; \
    224224        export BACKEND_HOST="@TEST_HOST@"; \
  • test/common.bash

    r5f3222b r4fb510d  
    1515        sleep 1
    1616    done
     17}
     18
     19
     20
     21# Usage: verbose_log [...]
     22#
     23# If VERBOSE is not empty, write a log message prefixed with the name
     24# of the calling function. The function is defined to a no-op
     25# otherwise.
     26if [ -n "${VERBOSE}" ]; then
     27    function verbose_log
     28    {
     29        echo "${FUNCNAME[1]}: ${@}"
     30    }
     31else
     32    function verbose_log
     33    {
     34        return
     35    }
     36fi
     37
     38
     39
     40# Usage: wait_ready COMMAND [TIMEOUT] [STEP]
     41#
     42# Wait until COMMAND terminates with success (zero exit code), or
     43# until the TIMEOUT (in milliseconds) expires. TIMEOUT defaults to
     44# $TEST_SERVICE_MAX_WAIT if unset. A TIMEOUT of zero means to try
     45# once.
     46#
     47# COMMAND is retried every STEP milliseconds, the default is
     48# $TEST_SERVICE_WAIT. Note that the last try may happen a little after
     49# TIMEOUT expires if STEP does not evenly divide it.
     50function wait_ready
     51{
     52    local command="${1}"
     53    if [ -z "${2}" ]; then
     54        local -i timeout="${TEST_SERVICE_MAX_WAIT}"
     55    else
     56        local -i timeout="${2}"
     57    fi
     58    local -i step="${3}"
     59    [ ${step} -gt 0 ] || step="${TEST_SERVICE_WAIT}"
     60    # convert step to seconds because that's what "sleep" needs
     61    local sec_step="$((${step} / 1000)).$((${step} % 1000))"
     62
     63    verbose_log "Waiting for \"${command}\" ..."
     64    local -i waited=0
     65    until eval "${command}"; do
     66        if [ "${waited}" -ge "${timeout}" ]; then
     67            echo "${FUNCNAME[0]}: Timed out waiting for \"${command}\"" \
     68                 "to succeed (waited ${waited} ms)." >&2
     69            return 1
     70        fi
     71        waited=$((waited + step));
     72        sleep "${sec_step}"
     73        verbose_log "waiting (${waited} ms)"
     74    done
     75    verbose_log "done (waited ${waited} ms)"
    1776}
    1877
  • test/runtests

    r5f3222b r4fb510d  
    1919
    2020BADVARS=0
    21 for v in APACHE2 TEST_HOST TEST_PORT TEST_QUERY_TIMEOUT TEST_MSVA_WAIT \
     21for v in APACHE2 TEST_HOST TEST_PORT TEST_QUERY_TIMEOUT TEST_SERVICE_WAIT \
    2222                 MSVA_PORT; do
    2323    if [ ! -v "$v" ]; then
     
    127127
    128128    printf "TESTING: initial MSVA verification\n"
    129     # set to 0 if MSVA is up
    130     ret=1
    131129    export MONKEYSPHERE_VALIDATION_AGENT_SOCKET="http://127.0.0.1:$MSVA_PORT"
    132130
    133     # convert TEST_MSVA_WAIT to seconds because that's what "sleep" expects
    134     TEST_MSVA_SLEEP="$((${TEST_MSVA_WAIT} / 1000)).$((${TEST_MSVA_WAIT} % 1000))"
    135     # wait at most TEST_MSVA_MAX_WAIT milliseconds for MSVA to get ready
    136     waited=0
    137     until [ ${ret} -eq 0 ] \
    138               || [ ${waited} -ge ${TEST_MSVA_MAX_WAIT} ]; do
    139         if msva-query-agent https "$(cat client.uid)" x509pem client < client/x509.pem
    140         then
    141             ret=0
    142         else
    143             echo "MSVA not ready yet"
    144         fi
    145         sleep "${TEST_MSVA_SLEEP}"
    146         waited=$((${waited} + ${TEST_MSVA_WAIT}))
    147     done
    148 
     131    msva_test_cmd="msva-query-agent https \"$(cat client.uid)\" x509pem client < client/x509.pem"
    149132    # check if MSVA is up, fail if not
    150     if [ ${ret} -eq 0 ]; then
     133    if wait_ready "${msva_test_cmd}"; then
    151134        printf "\nSUCCESS: initial MSVA verification\n"
    152135    else
     
    207190    fi
    208191    echo "---- Testing OCSP server ----"
    209     ocsptool --ask --nonce --load-issuer authority/x509.pem --load-cert server/x509.pem ${store_ocsp}
     192    wait_ready "ocsptool --ask --nonce --load-issuer authority/x509.pem --load-cert server/x509.pem ${store_ocsp}"
    210193    echo "---- OCSP test done ----"
    211194fi
Note: See TracChangeset for help on using the changeset viewer.