From 0766c1eb631190ee514a90e4d20a941f0a310054 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 27 Dec 2010 13:10:56 -0800 Subject: t0019: add CPU usage test This requires manual verification :< --- t/t0019-keepalive-cpu-usage.sh | 62 ++++++++++++++++++++++++++++++++++++++++++ t/times.ru | 6 ++++ 2 files changed, 68 insertions(+) create mode 100644 t/t0019-keepalive-cpu-usage.sh create mode 100644 t/times.ru 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 }' $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}" ] ] +} -- cgit v1.2.3-24-ge0c7