stream_response_epoll: our most "special" concurrency option yet
[rainbows.git] / t / t0000-simple-http.sh
blob57a7d59c44131ae71304c11cecadc0eda4eb0831
1 #!/bin/sh
2 . ./test-lib.sh
3 skip_models StreamResponseEpoll
4 t_plan 25 "simple HTTP connection keepalive/pipelining tests for $model"
6 t_begin "checking for config.ru for $model" && {
7 tbase=simple-http_$model.ru
8 test -f "$tbase"
11 t_begin "setup and start" && {
12 rainbows_setup
13 rainbows -D $tbase -c $unicorn_config
14 rainbows_wait_start
17 t_begin "pid file exists" && {
18 test -f $pid
21 t_begin "single request" && {
22 curl -sSfv http://$listen/
25 t_begin "handles client EOF gracefully" && {
26 printf 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n' | \
27 socat - TCP4:$listen > $tmp
28 dbgcat tmp
29 if grep 'HTTP.* 500' $tmp
30 then
31 die "500 error returned on client shutdown(SHUT_WR)"
33 check_stderr
36 dbgcat r_err
38 t_begin "two requests with keepalive" && {
39 curl -sSfv http://$listen/a http://$listen/b > $tmp 2>&1
42 dbgcat r_err
43 dbgcat tmp
45 t_begin "reused existing connection" && {
46 grep 'Re-using existing connection' < $tmp
49 t_begin "pipelining partial requests" && {
50 req='GET / HTTP/1.1\r\nHost: example.com\r\n'
52 cat $fifo > $tmp &
53 printf "$req"'\r\n'"$req"
54 sleep 1
55 printf 'Connection: close\r\n\r\n'
56 wait
57 echo ok > $ok
58 ) | socat - TCP:$listen > $fifo
60 dbgcat tmp
62 t_begin "two HTTP/1.1 responses" && {
63 test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
66 t_begin "two HTTP/1.1 200 OK responses" && {
67 test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
70 t_begin 'one "Connection: keep-alive" response' && {
71 test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
74 t_begin 'one "Connection: close" response' && {
75 test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
78 t_begin 'check subshell success' && {
79 test x"$(cat $ok)" = xok
83 t_begin "check stderr" && {
84 check_stderr
87 t_begin "burst pipelining requests" && {
88 req='GET / HTTP/1.1\r\nHost: example.com\r\n'
90 cat $fifo > $tmp &
91 printf "$req"'\r\n'"$req"'Connection: close\r\n\r\n'
92 wait
93 echo ok > $ok
94 ) | socat - TCP:$listen > $fifo
97 dbgcat tmp
98 dbgcat r_err
100 t_begin "got 2 HTTP/1.1 responses from pipelining" && {
101 test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
104 t_begin "got 2 HTTP/1.1 200 OK responses" && {
105 test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
108 t_begin "one keepalive connection" && {
109 test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
112 t_begin "second request closes connection" && {
113 test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
116 t_begin "subshell exited correctly" && {
117 test x"$(cat $ok)" = xok
120 t_begin "stderr log has no errors" && {
121 check_stderr
124 t_begin "HTTP/0.9 request should not return headers" && {
126 printf 'GET /\r\n'
127 cat $fifo > $tmp &
128 wait
129 echo ok > $ok
130 ) | socat - TCP:$listen > $fifo
133 dbgcat tmp
134 dbgcat r_err
136 t_begin "env.inspect should've put everything on one line" && {
137 test 1 -eq $(wc -l < $tmp)
140 t_begin "no headers in output" && {
141 if grep ^Connection: $tmp
142 then
143 die "Connection header found in $tmp"
144 elif grep ^HTTP/ $tmp
145 then
146 die "HTTP/ found in $tmp"
150 t_begin "killing succeeds" && {
151 kill $rainbows_pid
154 t_done