about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-05-20 15:17:21 -0700
committerEric Wong <normalperson@yhbt.net>2011-05-20 15:22:28 -0700
commitf4b084225b7115efecfbfb2b5d16da1f1da5c39e (patch)
tree162107be547f8fdc7e9c93fff4b70385c6a51c4d
parenta396de855e291d27d43454618031432634fe7d37 (diff)
downloadrainbows-f4b084225b7115efecfbfb2b5d16da1f1da5c39e.tar.gz
We can support it fully for a subset of concurrency models where
we have full control over buffering and HTTP/1.1 keepalive
clients.
-rw-r--r--t/large-file-response.ru3
-rw-r--r--t/t0044-autopush.sh119
2 files changed, 122 insertions, 0 deletions
diff --git a/t/large-file-response.ru b/t/large-file-response.ru
index 84163c1..aaa11c9 100644
--- a/t/large-file-response.ru
+++ b/t/large-file-response.ru
@@ -9,6 +9,9 @@ map "/rss" do
     [ 200, {}, [ ($1.to_i * 1024).to_s ] ]
   }
 end
+map "/pid" do
+  run lambda { |env| [ 200, {}, [ "#{Process.pid}\n" ] ] }
+end
 map "/" do
   run Rack::File.new(Dir.pwd)
 end
diff --git a/t/t0044-autopush.sh b/t/t0044-autopush.sh
new file mode 100644
index 0000000..e7705d6
--- /dev/null
+++ b/t/t0044-autopush.sh
@@ -0,0 +1,119 @@
+#!/bin/sh
+. ./test-lib.sh
+STRACE=$(which strace 2>/dev/null || :)
+if ! test -x "$STRACE"
+then
+        t_info "strace not found, skipping $T"
+        exit 0
+fi
+if test x"$(uname -s)" != xLinux
+then
+        t_info "Linux is the only supported OS for $T"
+        exit 0
+fi
+
+# these buffer internally in external libraries, so we can't detect when
+# to use TCP_CORK
+skip_models EventMachine NeverBlock
+skip_models Coolio CoolioThreadPool CoolioThreadSpawn
+skip_models Revactor Rev RevThreadPool RevThreadSpawn
+
+# not sure why, but we don't have time to care about Ruby 1.8 too much
+case $RUBY_VERSION in
+1.8.*) skip_models WriterThreadSpawn WriterThreadPool ;;
+esac
+
+t_plan 13 "Kgio autopush tests"
+
+t_begin "setup and start" && {
+        rainbows_setup $model 1
+        rtmpfiles strace_out
+        ed -s $unicorn_config <<EOF
+,s/^listen.*/listen "$listen", :tcp_nodelay => true, :tcp_nopush => true/
+w
+EOF
+        rainbows -D large-file-response.ru -c $unicorn_config -E none
+        rainbows_wait_start
+}
+
+t_begin "read worker pid" && {
+        worker_pid=$(curl -sSf http://$listen/pid)
+        kill -0 $worker_pid
+}
+
+t_begin "start strace on worker" && {
+        strace -p $worker_pid -e '!futex' -f -o $strace_out &
+        strace_pid=$!
+        sleep 1
+}
+
+t_begin "reading RSS uncorks" && {
+        curl -sSf http://$listen/rss >/dev/null
+        sleep 2
+        grep TCP_CORK $strace_out || :
+        test 2 -eq $(grep TCP_CORK $strace_out |wc -l)
+        fgrep 'SOL_TCP, TCP_CORK, [0], 4) = 0' $strace_out
+        fgrep 'SOL_TCP, TCP_CORK, [1], 4) = 0' $strace_out
+}
+
+t_begin "restart strace on worker" && {
+        kill -9 $strace_pid
+        wait
+
+        # dbgcat strace_out
+        > $strace_out
+        strace -p $worker_pid -e '!futex' -f -o $strace_out &
+        strace_pid=$!
+        sleep 1
+}
+
+t_begin "reading static file uncorks" && {
+        curl -sSf http://$listen/random_blob >/dev/null
+        sleep 2
+        test 2 -eq $(grep TCP_CORK $strace_out |wc -l)
+        fgrep 'SOL_TCP, TCP_CORK, [0], 4) = 0' $strace_out
+        fgrep 'SOL_TCP, TCP_CORK, [1], 4) = 0' $strace_out
+}
+
+t_begin "stop strace on worker" && {
+        kill -9 $strace_pid
+        wait
+}
+
+t_begin "enable sendfile" && {
+        echo >> $unicorn_config 'require "sendfile"'
+        kill -HUP $rainbows_pid
+        test xSTART = x"$(cat $fifo)"
+}
+
+t_begin "reread worker pid" && {
+        worker_pid=$(curl -sSf http://$listen/pid)
+        kill -0 $worker_pid
+}
+
+t_begin "restart strace on the worker" && {
+        # dbgcat strace_out
+        > $strace_out
+        strace -p $worker_pid -e '!futex' -f -o $strace_out &
+        strace_pid=$!
+        sleep 1
+}
+
+t_begin "HTTP/1.x GET on static file with sendfile uncorks" && {
+        curl -sSf http://$listen/random_blob >/dev/null
+        sleep 1
+        test 2 -eq $(grep TCP_CORK $strace_out |wc -l)
+        fgrep 'SOL_TCP, TCP_CORK, [0], 4) = 0' $strace_out
+        fgrep 'SOL_TCP, TCP_CORK, [1], 4) = 0' $strace_out
+}
+
+t_begin "killing succeeds" && {
+        kill -9 $strace_pid
+        wait
+        # dbgcat strace_out
+        kill $rainbows_pid
+}
+
+t_begin "check stderr" && check_stderr
+
+t_done