about summary refs log tree commit homepage
path: root/t/lib-simple-http.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/lib-simple-http.sh')
-rw-r--r--t/lib-simple-http.sh171
1 files changed, 117 insertions, 54 deletions
diff --git a/t/lib-simple-http.sh b/t/lib-simple-http.sh
index 235f4e3..cb0b28f 100644
--- a/t/lib-simple-http.sh
+++ b/t/lib-simple-http.sh
@@ -1,79 +1,142 @@
 #!/bin/sh
 . ./test-lib.sh
+t_plan 24 "simple HTTP connection keepalive/pipelining tests for $model"
 
-echo "simple HTTP connection keepalive/pipelining tests for $model"
+t_begin "checking for config.ru for $model" && {
+        tbase=$(expr "$T" : '^\(t....\)-').ru
+        test -f "$tbase"
+}
 
-tbase=$(expr "$T" : '^\(t....\)-').ru
-test -f "$tbase" || die "$tbase missing for $T"
+t_begin "setup and start" && {
+        rainbows_setup
+        rainbows -D $tbase -c $unicorn_config
+        rainbows_wait_start
+}
 
-rainbows_setup
-rainbows -D $tbase -c $unicorn_config
-rainbows_wait_start
+t_begin "pid file exists" && {
+        test -f $pid
+}
+
+t_begin "single request" && {
+        curl -sSfv http://$listen/
+}
 
-echo "single request"
-curl -sSfv http://$listen/
 dbgcat r_err
 
-echo "two requests with keepalive"
-curl -sSfv http://$listen/a http://$listen/b > $tmp 2>&1
+t_begin "two requests with keepalive" && {
+        curl -sSfv http://$listen/a http://$listen/b > $tmp 2>&1
+}
+
 dbgcat r_err
 dbgcat tmp
-grep 'Re-using existing connection' < $tmp
-
-echo "pipelining partial requests"
-req='GET / HTTP/1.1\r\nHost: example.com\r\n'
-(
-        printf "$req"'\r\n'"$req"
-        cat $fifo > $tmp &
-        sleep 1
-        printf 'Connection: close\r\n\r\n'
-        wait
-        echo ok > $ok
-) | socat - TCP:$listen > $fifo
 
+t_begin "reused existing connection" && {
+        grep 'Re-using existing connection' < $tmp
+}
+
+t_begin "pipelining partial requests" && {
+        req='GET / HTTP/1.1\r\nHost: example.com\r\n'
+        (
+                cat $fifo > $tmp &
+                printf "$req"'\r\n'"$req"
+                sleep 1
+                printf 'Connection: close\r\n\r\n'
+                wait
+                echo ok > $ok
+        ) | socat - TCP:$listen > $fifo
+}
 dbgcat tmp
 
-test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
-test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
-test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
-test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
-test x"$(cat $ok)" = xok
-check_stderr
+t_begin "two HTTP/1.1 responses" && {
+        test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
+}
+
+t_begin "two HTTP/1.1 200 OK responses" && {
+        test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
+}
+
+t_begin 'one "Connection: keep-alive" response' && {
+        test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
+}
+
+t_begin 'one "Connection: close" response' && {
+        test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
+}
+
+t_begin 'check subshell success' && {
+        test x"$(cat $ok)" = xok
+}
 
 
-echo "burst pipelining"
-req='GET / HTTP/1.1\r\nHost: example.com\r\n'
-(
-        printf "$req"'\r\n'"$req"'Connection: close\r\n\r\n'
-        cat $fifo > $tmp &
-        wait
-        echo ok > $ok
-) | socat - TCP:$listen > $fifo
+t_begin "check stderr" && {
+        check_stderr
+}
+
+t_begin "burst pipelining requests" && {
+        req='GET / HTTP/1.1\r\nHost: example.com\r\n'
+        (
+                cat $fifo > $tmp &
+                printf "$req"'\r\n'"$req"'Connection: close\r\n\r\n'
+                wait
+                echo ok > $ok
+        ) | socat - TCP:$listen > $fifo
+}
 
 dbgcat tmp
 dbgcat r_err
 
-test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
-test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
-test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
-test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
-test x"$(cat $ok)" = xok
+t_begin "got 2 HTTP/1.1 responses from pipelining" && {
+        test 2 -eq $(grep '^HTTP/1.1' $tmp | wc -l)
+}
+
+t_begin "got 2 HTTP/1.1 200 OK responses" && {
+        test 2 -eq $(grep '^HTTP/1.1 200 OK' $tmp | wc -l)
+}
+
+t_begin "one keepalive connection" && {
+        test 1 -eq $(grep '^Connection: keep-alive' $tmp | wc -l)
+}
+
+t_begin "second request closes connection" && {
+        test 1 -eq $(grep '^Connection: close' $tmp | wc -l)
+}
+
+t_begin "subshell exited correctly" && {
+        test x"$(cat $ok)" = xok
+}
 
-check_stderr
+t_begin "stderr log has no errors" && {
+        check_stderr
+}
 
-echo "HTTP/0.9 request should not return headers"
-(
-        printf 'GET /\r\n'
-        cat $fifo > $tmp &
-        wait
-        echo ok > $ok
-) | socat - TCP:$listen > $fifo
+t_begin "HTTP/0.9 request should not return headers" && {
+        (
+                printf 'GET /\r\n'
+                cat $fifo > $tmp &
+                wait
+                echo ok > $ok
+        ) | socat - TCP:$listen > $fifo
+}
 
 dbgcat tmp
 dbgcat r_err
-echo "env.inspect should've put everything on one line"
-test 1 -eq $(wc -l < $tmp)
-! grep ^Connection: $tmp
-! grep ^HTTP/ $tmp
 
-kill $(cat $pid)
+t_begin "env.inspect should've put everything on one line" && {
+        test 1 -eq $(wc -l < $tmp)
+}
+
+t_begin "no headers in output" && {
+        if grep ^Connection: $tmp
+        then
+                die "Connection header found in $tmp"
+        elif grep ^HTTP/ $tmp
+        then
+                die "HTTP/ found in $tmp"
+        fi
+}
+
+t_begin "killing succeeds" && {
+        kill $rainbows_pid
+}
+
+t_done