rev_thread_spawn: make 1.9 TeeInput performance tolerable
[rainbows.git] / t / t0000-simple-http.sh
blob173281bd19c6b06f5ab465b8ea371800122eee43
1 #!/bin/sh
2 . ./test-lib.sh
3 t_plan 24 "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 dbgcat r_err
26 t_begin "two requests with keepalive" && {
27 curl -sSfv http://$listen/a http://$listen/b > $tmp 2>&1
30 dbgcat r_err
31 dbgcat tmp
33 t_begin "reused existing connection" && {
34 grep 'Re-using existing connection' < $tmp
37 t_begin "pipelining partial requests" && {
38 req='GET / HTTP/1.1\r\nHost: example.com\r\n'
40 cat $fifo > $tmp &
41 printf "$req"'\r\n'"$req"
42 sleep 1
43 printf 'Connection: close\r\n\r\n'
44 wait
45 echo ok > $ok
46 ) | socat - TCP:$listen > $fifo
48 dbgcat tmp
50 t_begin "two HTTP/1.1 responses" && {
51 test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
54 t_begin "two HTTP/1.1 200 OK responses" && {
55 test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
58 t_begin 'one "Connection: keep-alive" response' && {
59 test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
62 t_begin 'one "Connection: close" response' && {
63 test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
66 t_begin 'check subshell success' && {
67 test x"$(cat $ok)" = xok
71 t_begin "check stderr" && {
72 check_stderr
75 t_begin "burst pipelining requests" && {
76 req='GET / HTTP/1.1\r\nHost: example.com\r\n'
78 cat $fifo > $tmp &
79 printf "$req"'\r\n'"$req"'Connection: close\r\n\r\n'
80 wait
81 echo ok > $ok
82 ) | socat - TCP:$listen > $fifo
85 dbgcat tmp
86 dbgcat r_err
88 t_begin "got 2 HTTP/1.1 responses from pipelining" && {
89 test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
92 t_begin "got 2 HTTP/1.1 200 OK responses" && {
93 test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
96 t_begin "one keepalive connection" && {
97 test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
100 t_begin "second request closes connection" && {
101 test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
104 t_begin "subshell exited correctly" && {
105 test x"$(cat $ok)" = xok
108 t_begin "stderr log has no errors" && {
109 check_stderr
112 t_begin "HTTP/0.9 request should not return headers" && {
114 printf 'GET /\r\n'
115 cat $fifo > $tmp &
116 wait
117 echo ok > $ok
118 ) | socat - TCP:$listen > $fifo
121 dbgcat tmp
122 dbgcat r_err
124 t_begin "env.inspect should've put everything on one line" && {
125 test 1 -eq $(wc -l < $tmp)
128 t_begin "no headers in output" && {
129 if grep ^Connection: $tmp
130 then
131 die "Connection header found in $tmp"
132 elif grep ^HTTP/ $tmp
133 then
134 die "HTTP/ found in $tmp"
138 t_begin "killing succeeds" && {
139 kill $rainbows_pid
142 t_done