coolio* + *epoll*: drop keepalive clients on SIGQUIT
[rainbows.git] / t / t0402-async-keepalive.sh
blob7b7b2e764b402f04443a97cd4b9f76c188a97128
1 #!/bin/sh
2 DELAY=${DELAY-1}
3 . ./test-lib.sh
4 case $model in
5 Coolio|NeverBlock|EventMachine) ;;
6 *)
7 t_info "skipping $T since it's not compatible with $model"
8 exit 0
9 ;;
10 esac
12 t_plan 12 "async_chunk_app test for test for $model"
14 CONFIG_RU=async_chunk_app.ru
16 t_begin "setup and start" && {
17 rainbows_setup
18 rtmpfiles a b c curl_err expect
20 # this does not does not support Rack::Lint
21 rainbows -E none -D $CONFIG_RU -c $unicorn_config
22 rainbows_wait_start
24 echo 'Hello World /0' >> $expect
25 echo 'Hello World /1' >> $expect
26 echo 'Hello World /2' >> $expect
29 t_begin "async.callback supports pipelining" && {
30 rm -f $tmp
31 t0=$(date +%s)
33 cat $fifo > $tmp &
34 printf 'GET /0 HTTP/1.1\r\nHost: example.com\r\n\r\n'
35 printf 'GET /1 HTTP/1.1\r\nHost: example.com\r\n\r\n'
36 printf 'GET /2 HTTP/1.0\r\nHost: example.com\r\n\r\n'
37 wait
38 ) | socat - TCP:$listen > $fifo
39 t1=$(date +%s)
40 elapsed=$(( $t1 - $t0 ))
41 t_info "elapsed=$elapsed $model.$0 ($t_current)"
42 test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | wc -l)"
43 test 3 -eq "$(grep '^Hello ' $tmp | wc -l)"
44 test 3 -eq "$(grep 'World ' $tmp | wc -l)"
47 t_begin "async.callback supports delayed pipelining" && {
48 rm -f $tmp
49 t0=$(date +%s)
51 cat $fifo > $tmp &
52 printf 'GET /0 HTTP/1.1\r\nHost: example.com\r\n\r\n'
53 sleep 1
54 printf 'GET /1 HTTP/1.1\r\nHost: example.com\r\n\r\n'
55 sleep 1
56 printf 'GET /2 HTTP/1.0\r\nHost: example.com\r\n\r\n'
57 wait
58 ) | socat - TCP:$listen > $fifo
59 t1=$(date +%s)
60 elapsed=$(( $t1 - $t0 ))
61 t_info "elapsed=$elapsed $model.$0 ($t_current)"
62 test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | wc -l)"
63 test 3 -eq "$(grep '^Hello ' $tmp | wc -l)"
64 test 3 -eq "$(grep 'World ' $tmp | wc -l)"
67 t_begin "async.callback supports pipelining with delay $DELAY" && {
68 rm -f $tmp
69 t0=$(date +%s)
71 cat $fifo > $tmp &
72 printf 'GET /0 HTTP/1.1\r\nX-Delay: %d\r\n' $DELAY
73 printf 'Host: example.com\r\n\r\n'
74 printf 'GET /1 HTTP/1.1\r\nX-Delay: %d\r\n' $DELAY
75 printf 'Host: example.com\r\n\r\n'
76 printf 'GET /2 HTTP/1.0\r\nX-Delay: %d\r\n' $DELAY
77 printf 'Host: example.com\r\n\r\n'
78 wait
79 ) | socat - TCP:$listen > $fifo
80 t1=$(date +%s)
81 elapsed=$(( $t1 - $t0 ))
82 min=$(( $DELAY * 3 ))
83 t_info "elapsed=$elapsed $model.$0 ($t_current) min=$min"
84 test $elapsed -ge $min
85 test 3 -eq "$(fgrep 'HTTP/1.1 200 OK' $tmp | wc -l)"
86 test 3 -eq "$(grep '^Hello ' $tmp | wc -l)"
87 test 3 -eq "$(grep 'World ' $tmp | wc -l)"
90 t_begin "async.callback supports keepalive" && {
91 t0=$(date +%s)
92 curl -v --no-buffer -sSf http://$listen/[0-2] > $tmp 2>> $curl_err
93 t1=$(date +%s)
94 elapsed=$(( $t1 - $t0 ))
95 t_info "elapsed=$elapsed $model.$0 ($t_current)"
96 cmp $expect $tmp
97 test 2 -eq "$(fgrep 'Re-using existing connection!' $curl_err |wc -l)"
98 rm -f $curl_err
101 t_begin "async.callback supports keepalive with delay $DELAY" && {
102 t0=$(date +%s)
103 curl -v --no-buffer -sSf -H "X-Delay: $DELAY" \
104 http://$listen/[0-2] > $tmp 2>> $curl_err
105 t1=$(date +%s)
106 elapsed=$(( $t1 - $t0 ))
107 min=$(( $DELAY * 3 ))
108 t_info "elapsed=$elapsed $model.$0 ($t_current) min=$min"
109 test $elapsed -ge $min
110 cmp $expect $tmp
111 test 2 -eq "$(fgrep 'Re-using existing connection!' $curl_err |wc -l)"
112 rm -f $curl_err
115 t_begin "send async requests off in parallel" && {
116 t0=$(date +%s)
117 curl --no-buffer -sSf http://$listen/[0-2] > $a 2>> $curl_err &
118 curl --no-buffer -sSf http://$listen/[0-2] > $b 2>> $curl_err &
119 curl --no-buffer -sSf http://$listen/[0-2] > $c 2>> $curl_err &
122 t_begin "wait for curl terminations" && {
123 wait
124 t1=$(date +%s)
125 elapsed=$(( $t1 - $t0 ))
126 t_info "elapsed=$elapsed"
129 t_begin "termination signal sent" && {
130 kill $rainbows_pid
133 t_begin "no errors from curl" && {
134 test ! -s $curl_err
137 t_begin "no errors in stderr" && check_stderr
139 t_begin "responses match expected" && {
140 cmp $expect $a
141 cmp $expect $b
142 cmp $expect $c
145 t_done