about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-27 13:10:56 -0800
committerEric Wong <normalperson@yhbt.net>2010-12-27 21:11:29 +0000
commit0766c1eb631190ee514a90e4d20a941f0a310054 (patch)
tree80e24a53af54a628d08cc43a904473f9af2817b4
parentd430bc3a481f897b4f515d5b7d0a0e239f8d2bb2 (diff)
downloadrainbows-0766c1eb631190ee514a90e4d20a941f0a310054.tar.gz
This requires manual verification :<
-rw-r--r--t/t0019-keepalive-cpu-usage.sh62
-rw-r--r--t/times.ru6
2 files changed, 68 insertions, 0 deletions
diff --git a/t/t0019-keepalive-cpu-usage.sh b/t/t0019-keepalive-cpu-usage.sh
new file mode 100644
index 0000000..e368709
--- /dev/null
+++ b/t/t0019-keepalive-cpu-usage.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+if test -z "$V" || test 0 -eq "$V"
+then
+        exit 0
+fi
+. ./test-lib.sh
+skip_models WriterThreadSpawn WriterThreadPool Base
+t_plan 6 "keepalive_timeout CPU usage tests for $model"
+
+t_begin "setup and start" && {
+        rainbows_setup $model 50 666
+        grep 'worker_connections 50' $unicorn_config
+        grep 'keepalive_timeout 666' $unicorn_config
+        rainbows -E deployment -D times.ru -c $unicorn_config
+        rainbows_wait_start
+}
+
+t_begin 'read current times' && {
+        eval "$(curl -sSf http://$listen/)"
+        before_utime=$utime
+        before_stime=$stime
+        echo "utime=$utime stime=$stime"
+}
+
+t_begin 'keepalive connections' && {
+        listen=$listen $RUBY -rsocket -e '
+host, port = ENV["listen"].split(/:/)
+port = port.to_i
+socks = (1..49).map do |i|
+  s = TCPSocket.new(host, port)
+  # need to write something to get around deferred accepts
+  s.write "GET /#{i} HTTP/1.1\r\nHost: example.com\r\n\r\n"
+  s.readpartial 16384
+  s
+end
+sleep
+        ' &
+        ruby_pid=$!
+        for i in $(awk 'BEGIN { for(i=0;i<60;++i) print i }' </dev/null)
+        do
+                sleep 1
+                eval "$(curl -sSf http://$listen/)"
+                echo "utime[$i] $before_utime => $utime" \
+                     "stime[$i] $before_stime => $stime"
+        done
+        kill $ruby_pid
+}
+
+t_begin "times not unreasonable" && {
+        echo "utime: $before_utime => $utime" \
+             "stime: $before_stime => $stime"
+}
+
+t_begin "killing succeeds" && {
+        kill $rainbows_pid
+}
+
+t_begin "check stderr" && {
+        check_stderr
+}
+
+t_done
diff --git a/t/times.ru b/t/times.ru
new file mode 100644
index 0000000..8be3ed4
--- /dev/null
+++ b/t/times.ru
@@ -0,0 +1,6 @@
+use Rack::ContentLength
+use Rack::ContentType, "text/plain"
+run lambda { |env|
+  t = Process.times
+  [ 200, {}, [ "utime=#{t.utime} stime=#{t.stime}" ] ]
+}