Annotation of parser3/tests/httpd/response-timeout/run_tests.sh, revision 1.1

1.1     ! moko        1: #!/bin/sh
        !             2: # $response:timeout: the request which takes too long is interrupted, in parallel mode the process is killed if it does not stop
        !             3: 
        !             4: PARSER=`pwd`/../../../src/targets/cgi/parser3
        !             5: PORT=8103
        !             6: 
        !             7: if command -v curl >/dev/null 2>&1; then
        !             8:        get() { # GET /?name
        !             9:                curl -s -m 6 -w ' [%{http_code}]' http://localhost:$PORT/?$1
        !            10:                echo
        !            11:        }
        !            12: else
        !            13:        get() { # GET /?name, fetch (FreeBSD) does not tell the status: [200] or nothing
        !            14:                fetch -q -T 6 -o - http://localhost:$PORT/?$1 2>/dev/null && echo ' [200]' || echo ' [000]'
        !            15:        }
        !            16: fi
        !            17: 
        !            18: fast() { # GET /?name, must be answered at once
        !            19:        start=`date +%s`
        !            20:        get $1
        !            21:        [ `date +%s` -lt $((start+4)) ] || echo "too slow"
        !            22: }
        !            23: 
        !            24: alive() { # the process exists and is not a zombie
        !            25:        pid=$1
        !            26:        set -- `ps -o stat= -p $pid 2>/dev/null`
        !            27:        [ -n "$1" ] && [ "${1#Z}" = "$1" ]
        !            28: }
        !            29: 
        !            30: run() { # httpd mode
        !            31:        echo "=== $1"
        !            32:        rm -f site/parser3.log site/hang.pid site/hang-child.pid site/detach.pid
        !            33:        (cd site && TEST_HTTPD_MODE=$1 CGI_PARSER_CONFIG=`pwd`/config.p exec $PARSER -p $PORT) 2>/dev/null & # threads print the libxml warnings to stderr
        !            34:        server=$!
        !            35:        # wait for the server listens
        !            36:        for i in 1 2 3 4 5; do nc -z localhost $PORT 2>/dev/null && break; sleep 0.2; done
        !            37: 
        !            38:        echo "sleep:"; get sleep
        !            39:        echo "loop:"; get loop
        !            40:        echo "sleep in try:"; get try
        !            41:        echo "loop in try:"; get try-loop
        !            42:        echo "sleep in nested try with finally:"; get try-nested
        !            43:        echo "timeout cancelled:"; get cancel
        !            44:        echo "timeout restarted:"; get restart
        !            45:        echo "hang in the executed program:"; get hang
        !            46:        if [ "$1" = sequental ]; then
        !            47:                # the server is busy with this request, the connection to it is accepted and not answered
        !            48:                echo "http client waiting for the answer of the busy server itself:"; fast self
        !            49:        fi
        !            50:        echo "interruption swallowed in a libxml callback:"; fast xml-callback
        !            51:        echo "the program and its child are killed:"
        !            52:        for f in hang.pid hang-child.pid; do alive `cat site/$f` && echo "$f is alive"; done
        !            53:        if [ "$1" = parallel ]; then
        !            54:                # the program which has left holds the connection if it is inherited, the killed process can't close it
        !            55:                echo "@unhandled_exception is slow, the process is killed, the connection is closed at once:"; fast slow-unhandled
        !            56:        fi
        !            57:        echo "the server goes on:"; get quick
        !            58: 
        !            59:        kill $server; wait $server 2>/dev/null
        !            60:        # the program which has left lives on
        !            61:        [ -f site/detach.pid ] && kill `cat site/detach.pid` 2>/dev/null
        !            62:        grep -o "response timeout (1 s) exceeded, process killed" site/parser3.log 2>/dev/null | sort -u
        !            63: }
        !            64: 
        !            65: {
        !            66: run sequental
        !            67: run parallel
        !            68: run threaded
        !            69: } >tests.log 2>&1
        !            70: 
        !            71: rm -f site/parser3.log site/hang.pid site/hang-child.pid site/detach.pid
        !            72: diff -u ok.log tests.log

E-mail: