event_machine: factor out async.callback handling
[rainbows.git] / t / t0000-simple-http.sh
blob6f4d7385a86a0cb30c002b036e85c4d73dc5cd85
1 #!/bin/sh
2 . ./test-lib.sh
3 t_plan 25 "simple HTTP connection keepalive/pipelining tests for $model"
5 t_begin "checking for config.ru for $model" && {
6 tbase=simple-http_$model.ru
7 test -f "$tbase"
10 t_begin "setup and start" && {
11 rainbows_setup
12 rainbows -D $tbase -c $unicorn_config
13 rainbows_wait_start
16 t_begin "pid file exists" && {
17 test -f $pid
20 t_begin "single request" && {
21 curl -sSfv http://$listen/
24 t_begin "handles client EOF gracefully" && {
25 printf 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n' | \
26 socat - TCP4:$listen > $tmp
27 dbgcat tmp
28 if grep 'HTTP.* 500' $tmp
29 then
30 die "500 error returned on client shutdown(SHUT_WR)"
32 check_stderr
35 dbgcat r_err
37 t_begin "two requests with keepalive" && {
38 curl -sSfv http://$listen/a http://$listen/b > $tmp 2>&1
41 dbgcat r_err
42 dbgcat tmp
44 t_begin "reused existing connection" && {
45 grep 'Re-using existing connection' < $tmp
48 t_begin "pipelining partial requests" && {
49 req='GET / HTTP/1.1\r\nHost: example.com\r\n'
51 cat $fifo > $tmp &
52 printf "$req"'\r\n'"$req"
53 sleep 1
54 printf 'Connection: close\r\n\r\n'
55 wait
56 echo ok > $ok
57 ) | socat - TCP:$listen > $fifo
59 dbgcat tmp
61 t_begin "two HTTP/1.1 responses" && {
62 test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
65 t_begin "two HTTP/1.1 200 OK responses" && {
66 test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
69 t_begin 'one "Connection: keep-alive" response' && {
70 test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
73 t_begin 'one "Connection: close" response' && {
74 test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
77 t_begin 'check subshell success' && {
78 test x"$(cat $ok)" = xok
82 t_begin "check stderr" && {
83 check_stderr
86 t_begin "burst pipelining requests" && {
87 req='GET / HTTP/1.1\r\nHost: example.com\r\n'
89 cat $fifo > $tmp &
90 printf "$req"'\r\n'"$req"'Connection: close\r\n\r\n'
91 wait
92 echo ok > $ok
93 ) | socat - TCP:$listen > $fifo
96 dbgcat tmp
97 dbgcat r_err
99 t_begin "got 2 HTTP/1.1 responses from pipelining" && {
100 test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
103 t_begin "got 2 HTTP/1.1 200 OK responses" && {
104 test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
107 t_begin "one keepalive connection" && {
108 test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
111 t_begin "second request closes connection" && {
112 test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
115 t_begin "subshell exited correctly" && {
116 test x"$(cat $ok)" = xok
119 t_begin "stderr log has no errors" && {
120 check_stderr
123 t_begin "HTTP/0.9 request should not return headers" && {
125 printf 'GET /\r\n'
126 cat $fifo > $tmp &
127 wait
128 echo ok > $ok
129 ) | socat - TCP:$listen > $fifo
132 dbgcat tmp
133 dbgcat r_err
135 t_begin "env.inspect should've put everything on one line" && {
136 test 1 -eq $(wc -l < $tmp)
139 t_begin "no headers in output" && {
140 if grep ^Connection: $tmp
141 then
142 die "Connection header found in $tmp"
143 elif grep ^HTTP/ $tmp
144 then
145 die "HTTP/ found in $tmp"
149 t_begin "killing succeeds" && {
150 kill $rainbows_pid
153 t_done