source: mod_gnutls/test/runtests @ dda3acf

debian/masterdebian/stretch-backportsjessie-backportsupstream
Last change on this file since dda3acf was dda3acf, checked in by Thomas Klute <thomas2.klute@…>, 5 years ago

Speed up tests with background sleep

Until now, a significant part of test run time was spent waiting
TEST_QUERY_DELAY seconds for a response from the server. The sleep call
used for that keeps the pipe from the subshell to gnutls-cli open,
without it, gnutls-cli would terminate as soon as sed is done, leading
to failing tests. However, in many cases the wait is longer than
necessary for the test.

Sending sleep to the background allows the test case to proceed instead
of waiting for sleep to return, but has the disadvantage of leaving the
sleep process dangling until it eventually times out. I think the
significantly reduced test execution time is worth it.

  • Property mode set to 100755
File size: 3.7 KB
RevLine 
[4b53371]1#!/bin/bash
2
3# Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
4
5set -e
6
7tests="${1##t-}"
8
[9a06bbd]9if [ -n "${TEST_LOCK}" ]; then
10    TEST_LOCK="$(realpath ${TEST_LOCK})"
11    flock_cmd="flock -w 10 ${TEST_LOCK}"
12fi
13
[4b53371]14BADVARS=0
[e3cbda4]15for v in TEST_HOST TEST_IP TEST_PORT TEST_QUERY_DELAY TEST_GAP MSVA_PORT; do
[4b53371]16    if [ ! -v "$v" ]; then
17        printf "You need to set the %s environment variable\n" "$v" >&2
18        BADVARS=1
19    fi
20done
21
22if [ 0 != "$BADVARS" ]; then
23    exit 1
24fi
25
26if [ . != "$(dirname "$0")" ]; then
[8dcf888]27    printf "You should only run this mod-gnutls test suite from the test/ directory of the mod_gnutls source.\n" >&2
[4b53371]28    exit 1
29fi
30
[e3cbda4]31function stop_msva() {
32    kill %1
33}
34
[4b53371]35function apache_down_err() {
36    printf "FAILURE: %s\n" "$TEST_NAME"
37    /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k stop || true
38    if [ -e output ]; then
39        printf "\ngnutls-cli outputs:\n"
40        diff -u output <( tail -n "$(wc -l < output)" "$output" ) || true
41    fi
42    printf "\nApache error logs:\n"
43    tail "../../logs/${TEST_NAME}.error.log"
[302965e]44    if [ -n "${USE_MSVA}" ]; then
45        stop_msva
46    fi
[4b53371]47}
48
49if [ -z "$tests" ] ; then
50    tests=./tests/*
51else
52    tests=./tests/"$(printf "%02d" "$tests")"_*
53fi
54
[302965e]55if [ -n "${USE_MSVA}" ]; then
56    GNUPGHOME=$(pwd)/msva.gnupghome MSVA_KEYSERVER_POLICY=never monkeysphere-validation-agent &
57    trap stop_msva EXIT
[e3cbda4]58
[302965e]59    sleep "$TEST_GAP"
[e3cbda4]60
[302965e]61    printf "TESTING: initial MSVA verification\n"
62    MONKEYSPHERE_VALIDATION_AGENT_SOCKET="http://127.0.0.1:$MSVA_PORT" msva-query-agent https "$(cat client.uid)" x509pem client < client/x509.pem
63    printf "\nSUCCESS: initial MSVA verification\n"
64fi
[e3cbda4]65
[9a06bbd]66for t in $tests; do
67    if [ -z "${flock_cmd}" ]; then
68        echo "Warning: no lock file set"
69        sleep "$TEST_GAP"
70    fi
[4b53371]71    export TEST_NAME="$(basename "$t")"
72    output="../../outputs/${TEST_NAME}.output"
73    rm -f "$output"
74    cd "$t"
75    if [ -e fail.* ]; then
76        EXPECTED_FAILURE="$(printf " (expected: %s)" fail.*)"
77    else
78        unset EXPECTED_FAILURE
79    fi
80    printf "TESTING: %s%s\n" "$TEST_NAME" "$EXPECTED_FAILURE"
81    trap apache_down_err EXIT
[302965e]82    if [ -n "${USE_MSVA}" ]; then
[9e35c48]83        MONKEYSPHERE_VALIDATION_AGENT_SOCKET="http://127.0.0.1:$MSVA_PORT" \
84            ${flock_cmd} \
[9a06bbd]85            /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k start \
86            || [ -e fail.server ]
[302965e]87    else
[9a06bbd]88        ${flock_cmd} \
89            /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k start \
90            || [ -e fail.server ]
[302965e]91    fi
[4b53371]92
[dda3acf]93    # The sleep call keeps the pipe from the subshell to gnutls-cli
94    # open. Without it gnutls-cli would terminate as soon as sed is
95    # done, and not wait for a response from the server, leading to
96    # failing tests. Sending sleep to the background allows the test
97    # case to proceed instead of waiting for it to return, but has the
98    # disadvantage of leaving the sleep process dangling until it
99    # eventually times out. Still preferable to a fixed delay.
100    if (sed "s/__HOSTNAME__/${TEST_HOST}/" <./input && \
101        sleep "${TEST_QUERY_DELAY}" &) | \
102        gnutls-cli -p "${TEST_PORT}" $(cat ./gnutls-cli.args) "${TEST_HOST}" \
103        >"$output";
104    then
[4b53371]105        if [ -e fail* ]; then
106            printf "%s should have failed but succeeded\n" "$(basename "$t")" >&2
107            exit 1
108        fi
109    else
110        if [ ! -e fail* ]; then
111            printf "%s should have succeeded but failed\n" "$(basename "$t")" >&2
112            exit 1
113        fi
114    fi
[dda3acf]115
[4b53371]116    if [ -e output ] ; then
117        diff -q -u output <( tail -n "$(wc -l < output)" "$output" )
118    fi
119    /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k stop || [ -e fail.server ]
[302965e]120    if [ -n "${USE_MSVA}" ]; then
121        trap stop_msva EXIT
122    else
123        trap - EXIT
124    fi
[4b53371]125    printf "SUCCESS: %s\n" "$TEST_NAME"
126    cd ../..
127done
[e3cbda4]128
[302965e]129if [ -n "${USE_MSVA}" ]; then
130    stop_msva
131fi
Note: See TracBrowser for help on using the repository browser.