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