t0019: add CPU usage test
[rainbows.git] / t / t0019-keepalive-cpu-usage.sh
blobe36870926c1e9e337767308d859e115f1360c1b0
1 #!/bin/sh
2 if test -z "$V" || test 0 -eq "$V"
3 then
4 exit 0
5 fi
6 . ./test-lib.sh
7 skip_models WriterThreadSpawn WriterThreadPool Base
8 t_plan 6 "keepalive_timeout CPU usage tests for $model"
10 t_begin "setup and start" && {
11 rainbows_setup $model 50 666
12 grep 'worker_connections 50' $unicorn_config
13 grep 'keepalive_timeout 666' $unicorn_config
14 rainbows -E deployment -D times.ru -c $unicorn_config
15 rainbows_wait_start
18 t_begin 'read current times' && {
19 eval "$(curl -sSf http://$listen/)"
20 before_utime=$utime
21 before_stime=$stime
22 echo "utime=$utime stime=$stime"
25 t_begin 'keepalive connections' && {
26 listen=$listen $RUBY -rsocket -e '
27 host, port = ENV["listen"].split(/:/)
28 port = port.to_i
29 socks = (1..49).map do |i|
30 s = TCPSocket.new(host, port)
31 # need to write something to get around deferred accepts
32 s.write "GET /#{i} HTTP/1.1\r\nHost: example.com\r\n\r\n"
33 s.readpartial 16384
35 end
36 sleep
37 ' &
38 ruby_pid=$!
39 for i in $(awk 'BEGIN { for(i=0;i<60;++i) print i }' </dev/null)
41 sleep 1
42 eval "$(curl -sSf http://$listen/)"
43 echo "utime[$i] $before_utime => $utime" \
44 "stime[$i] $before_stime => $stime"
45 done
46 kill $ruby_pid
49 t_begin "times not unreasonable" && {
50 echo "utime: $before_utime => $utime" \
51 "stime: $before_stime => $stime"
54 t_begin "killing succeeds" && {
55 kill $rainbows_pid
58 t_begin "check stderr" && {
59 check_stderr
62 t_done