about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-17 22:42:56 -0700
committerEric Wong <normalperson@yhbt.net>2009-10-17 22:42:56 -0700
commit61a50566ea0799a9b19c3dcfdf9b1ae5ea083dd2 (patch)
treef28eeeb655e378fc187e28199af62d37aa1c98c2 /t
parent0719c5a7ac09078c810507244a86ba44623757c4 (diff)
downloadrainbows-61a50566ea0799a9b19c3dcfdf9b1ae5ea083dd2.tar.gz
We support pipelining, keepalive, and even HTTP/0.9!
Diffstat (limited to 't')
-rw-r--r--t/lib-simple-http.sh95
-rwxr-xr-xt/t0000-basic.sh37
-rwxr-xr-xt/t1000-thread-pool-basic.sh42
-rwxr-xr-xt/t2000-thread-spawn-basic.sh38
-rwxr-xr-xt/t3000-revactor-basic.sh39
-rwxr-xr-xt/t3001-revactor-pipeline.sh45
-rwxr-xr-xt/t4000-rev-basic.sh50
7 files changed, 100 insertions, 246 deletions
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 <<EOF
+listen "$listen"
+pid "$pid"
+stderr_path "$r_err"
+stdout_path "$r_out"
+EOF
+if test x$model != xany
+then
+        echo "Rainbows! { use :$model }" >> $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 <<EOF
-stderr_path "$r_err"
-stdout_path "$r_out"
-listen "$listen"
-pid "$pid"
-Rainbows! do
-  use :ThreadPool
-  worker_connections $nr_thread
-end
-EOF
-
-rainbows -D t1000.ru -c $unicorn_config
-wait_for_pid $pid
-
-start=$(date +%s)
-for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
-do
-        ( curl -sSf http://$listen/$i >> $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 <<EOF
-stderr_path "$r_err"
-stdout_path "$r_out"
-listen "$listen"
-pid "$pid"
-Rainbows! do
-  use :ThreadSpawn
-  worker_connections $nr_thread
-end
-EOF
-
-rainbows -D t2000.ru -c $unicorn_config
-wait_for_pid $pid
-
-start=$(date +%s)
-for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
-do
-        ( curl -sSf http://$listen/$i >> $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 <<EOF
-listen "$listen"
-pid "$pid"
-stderr_path "$r_err"
-stdout_path "$r_out"
-Rainbows! do
-  use :Revactor
-  worker_connections $nr_actor
-end
-EOF
-
-rainbows -D t3000.ru -c $unicorn_config
-wait_for_pid $pid
-
-start=$(date +%s)
-for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
-do
-        ( curl -sSf http://$listen/$i >> $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 <<EOF
-stderr_path "$r_err"
-stdout_path "$r_out"
-listen "$listen"
-pid "$pid"
-Rainbows! do
-  use :Revactor
-end
-EOF
-
-rainbows -D t0000.ru -c $unicorn_config
-wait_for_pid $pid
-
-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)
-
-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 <<EOF
-listen "$listen"
-pid "$pid"
-stderr_path "$r_err"
-stdout_path "$r_out"
-Rainbows! do
-  use :Rev
-  worker_connections 50
-end
-EOF
-
-rainbows -D t4000.ru -c $unicorn_config
-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: 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