From 61a50566ea0799a9b19c3dcfdf9b1ae5ea083dd2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 17 Oct 2009 22:42:56 -0700 Subject: tests: common basic HTTP tests for all models We support pipelining, keepalive, and even HTTP/0.9! --- t/lib-simple-http.sh | 95 +++++++++++++++++++++++++++++++++++++++++++ t/t0000-basic.sh | 37 +---------------- t/t1000-thread-pool-basic.sh | 42 +------------------ t/t2000-thread-spawn-basic.sh | 38 +---------------- t/t3000-revactor-basic.sh | 39 +----------------- t/t3001-revactor-pipeline.sh | 45 -------------------- t/t4000-rev-basic.sh | 50 +---------------------- 7 files changed, 100 insertions(+), 246 deletions(-) create mode 100644 t/lib-simple-http.sh delete mode 100755 t/t3001-revactor-pipeline.sh diff --git a/t/lib-simple-http.sh b/t/lib-simple-http.sh new file mode 100644 index 0000000..8d09082 --- /dev/null +++ b/t/lib-simple-http.sh @@ -0,0 +1,95 @@ +#!/bin/sh +. ./test-lib.sh + +echo "simple HTTP connection keepalive/pipelining tests for $model" + +tbase=$(expr "$T" : '^\(t....\)-').ru +test -f "$tbase" || die "$tbase missing for $T" + +eval $(unused_listen) +rtmpfiles unicorn_config pid r_err r_out tmp fifo ok +rm -f $fifo +mkfifo $fifo + +cat > $unicorn_config <> $unicorn_config +fi + +rainbows -D $tbase -c $unicorn_config +wait_for_pid $pid + +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 +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 + +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 +! grep Error $r_err + + +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 + +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 + +! grep Error $r_err + + +echo "HTTP/0.9 request should not return headers" +( + printf 'GET /\r\n\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) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 1ba3f43..7942942 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -1,37 +1,2 @@ #!/bin/sh -. ./test-lib.sh - -eval $(unused_listen) -rtmpfiles pid tmp ok fifo - -rm -f $fifo -mkfifo $fifo - -rainbows -D t0000.ru -l $listen --pid $pid & -wait_for_pid $pid - -echo "single request" -curl -sSfv http://$listen/ - -echo "two requests with keepalive" -curl -sSfv http://$listen/a http://$listen/b > $tmp 2>&1 -grep 'Re-using existing connection' < $tmp - -echo "pipelining partial requests" -req='GET / HTTP/1.1\r\nHost: foo\r\n' -( - printf "$req"'\r\n'"$req" - cat $fifo > $tmp & - sleep 1 - printf 'Connection: close\r\n\r\n' - echo ok > $ok -) | socat - TCP:$listen > $fifo - -kill $(cat $pid) - -# sed -ne 's/^/------/p' < $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 +. ./lib-simple-http.sh diff --git a/t/t1000-thread-pool-basic.sh b/t/t1000-thread-pool-basic.sh index 1510ab6..7942942 100755 --- a/t/t1000-thread-pool-basic.sh +++ b/t/t1000-thread-pool-basic.sh @@ -1,42 +1,2 @@ #!/bin/sh -. ./test-lib.sh - -eval $(unused_listen) -rtmpfiles unicorn_config curl_out curl_err pid r_err r_out - -nr_client=30 -nr_thread=10 - -cat > $unicorn_config <> $curl_out 2>> $curl_err ) & -done -wait -echo elapsed=$(( $(date +%s) - $start )) - -kill $(cat $pid) - -! test -s $curl_err -test x"$(wc -l < $curl_out)" = x$nr_client - -nr=$(sort < $curl_out | uniq | wc -l) - -test "$nr" -le $nr_thread -test "$nr" -gt 1 - -! grep Error $r_err +. ./lib-simple-http.sh diff --git a/t/t2000-thread-spawn-basic.sh b/t/t2000-thread-spawn-basic.sh index 37aa029..7942942 100755 --- a/t/t2000-thread-spawn-basic.sh +++ b/t/t2000-thread-spawn-basic.sh @@ -1,38 +1,2 @@ #!/bin/sh -. ./test-lib.sh - -eval $(unused_listen) -rtmpfiles unicorn_config curl_out curl_err pid r_err r_out - -nr_client=30 -nr_thread=10 - -cat > $unicorn_config <> $curl_out 2>> $curl_err ) & -done -wait -echo elapsed=$(( $(date +%s) - $start )) - -kill $(cat $pid) - -! test -s $curl_err -test x"$(wc -l < $curl_out)" = x$nr_client -nr=$(sort < $curl_out | uniq | wc -l) -test "$nr" -eq $nr_client -! grep Error $r_err +. ./lib-simple-http.sh diff --git a/t/t3000-revactor-basic.sh b/t/t3000-revactor-basic.sh index 856c1ca..7942942 100755 --- a/t/t3000-revactor-basic.sh +++ b/t/t3000-revactor-basic.sh @@ -1,39 +1,2 @@ #!/bin/sh -. ./test-lib.sh - -eval $(unused_listen) -rtmpfiles unicorn_config curl_out curl_err pid r_err r_out - -nr_client=30 -nr_actor=10 - -cat > $unicorn_config <> $curl_out 2>> $curl_err ) & -done -wait -echo elapsed=$(( $(date +%s) - $start )) - -kill $(cat $pid) - -! test -s $curl_err -test x"$(wc -l < $curl_out)" = x$nr_client -nr=$(sort < $curl_out | uniq | wc -l) - -test "$nr" -eq 1 -! grep Error $r_err +. ./lib-simple-http.sh diff --git a/t/t3001-revactor-pipeline.sh b/t/t3001-revactor-pipeline.sh deleted file mode 100755 index e00bdca..0000000 --- a/t/t3001-revactor-pipeline.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -. ./test-lib.sh - -eval $(unused_listen) -rtmpfiles unicorn_config curl_out curl_err pid fifo tmp ok r_err r_out - -rm -f $fifo -mkfifo $fifo - -cat > $unicorn_config < $tmp 2>&1 -grep 'Re-using existing connection' < $tmp - -echo "pipelining partial requests" -req='GET / HTTP/1.1\r\nHost: foo\r\n' -( - printf "$req"'\r\n'"$req" - cat $fifo > $tmp & - sleep 1 - printf 'Connection: close\r\n\r\n' - echo ok > $ok -) | socat - TCP:$listen > $fifo - -kill $(cat $pid) - -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 -! grep Error $r_err diff --git a/t/t4000-rev-basic.sh b/t/t4000-rev-basic.sh index df1f338..7942942 100755 --- a/t/t4000-rev-basic.sh +++ b/t/t4000-rev-basic.sh @@ -1,50 +1,2 @@ #!/bin/sh -. ./test-lib.sh - -eval $(unused_listen) -rtmpfiles unicorn_config pid r_err r_out tmp fifo ok -rm -f $fifo -mkfifo $fifo - -nr_client=30 - -cat > $unicorn_config < $tmp 2>&1 -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 - -kill $(cat $pid) - -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 -! grep Error $r_err +. ./lib-simple-http.sh -- cgit v1.2.3-24-ge0c7