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

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
1.3       moko       33:        # not in a subshell: on FreeBSD $! is the subshell then, the killed one is not the server
                     34:        cd site
1.4     ! moko       35:        TEST_HTTPD_MODE=$1 CGI_PARSER_CONFIG=`pwd`/config.p $PARSER -p $PORT &
1.1       moko       36:        server=$!
1.3       moko       37:        cd ..
1.1       moko       38:        # wait for the server listens
                     39:        for i in 1 2 3 4 5; do nc -z localhost $PORT 2>/dev/null && break; sleep 0.2; done
                     40: 
                     41:        echo "sleep:"; get sleep
                     42:        echo "loop:"; get loop
                     43:        echo "sleep in try:"; get try
                     44:        echo "loop in try:"; get try-loop
                     45:        echo "sleep in nested try with finally:"; get try-nested
                     46:        echo "timeout cancelled:"; get cancel
                     47:        echo "timeout restarted:"; get restart
                     48:        echo "hang in the executed program:"; get hang
                     49:        if [ "$1" = sequental ]; then
                     50:                # the server is busy with this request, the connection to it is accepted and not answered
                     51:                echo "http client waiting for the answer of the busy server itself:"; fast self
                     52:        fi
                     53:        echo "interruption swallowed in a libxml callback:"; fast xml-callback
                     54:        echo "the program and its child are killed:"
                     55:        for f in hang.pid hang-child.pid; do alive `cat site/$f` && echo "$f is alive"; done
                     56:        if [ "$1" = parallel ]; then
                     57:                # the program which has left holds the connection if it is inherited, the killed process can't close it
                     58:                echo "@unhandled_exception is slow, the process is killed, the connection is closed at once:"; fast slow-unhandled
                     59:        fi
                     60:        echo "the server goes on:"; get quick
                     61: 
1.2       moko       62:        { kill $server; wait $server; } 2>/dev/null
1.1       moko       63:        # the program which has left lives on
                     64:        [ -f site/detach.pid ] && kill `cat site/detach.pid` 2>/dev/null
                     65:        grep -o "response timeout (1 s) exceeded, process killed" site/parser3.log 2>/dev/null | sort -u
                     66: }
                     67: 
                     68: {
                     69: run sequental
                     70: run parallel
                     71: run threaded
                     72: } >tests.log 2>&1
                     73: 
                     74: rm -f site/parser3.log site/hang.pid site/hang-child.pid site/detach.pid
                     75: diff -u ok.log tests.log

E-mail: