sync_close: This fix breakage from Ruby-trunk r50118
[rainbows.git] / t / t0044-autopush.sh
blob103f9fcdfd6ee1c8278051baf760310edcf5b8d5
1 #!/bin/sh
2 . ./test-lib.sh
3 STRACE=$(which strace 2>/dev/null || :)
4 if ! test -x "$STRACE"
5 then
6 t_info "strace not found, skipping $T"
7 exit 0
8 fi
9 if test x"$(uname -s)" != xLinux
10 then
11 t_info "Linux is the only supported OS for $T"
12 exit 0
15 # these buffer internally in external libraries, so we can't detect when
16 # to use TCP_CORK
17 skip_models EventMachine NeverBlock
18 skip_models StreamResponseEpoll
19 skip_models Coolio CoolioThreadPool CoolioThreadSpawn
20 skip_models Revactor Rev RevThreadPool RevThreadSpawn
22 # not sure why, but we don't have time to care about Ruby 1.8 too much
23 case $RUBY_VERSION in
24 1.8.*) skip_models WriterThreadSpawn WriterThreadPool ;;
25 esac
27 t_plan 13 "Kgio autopush tests"
29 start_strace () {
30 # dbgcat strace_out
31 > $strace_out
32 sleep 1
33 strace -p $worker_pid -e '!futex' -f -o $strace_out &
34 strace_pid=$!
35 while ! test -s $strace_out; do sleep 1; done
38 check_TCP_CORK () {
39 nr=0
40 while test 2 -gt $(grep TCP_CORK $strace_out | count_lines)
42 nr=$(( $nr + 1 ))
43 if test $nr -gt 30
44 then
45 dbgcat strace_out
46 die "waited too long ($nr seconds) for TCP_CORK"
48 sleep 1
49 done
51 test 2 -eq $(grep TCP_CORK $strace_out | count_lines)
52 fgrep 'SOL_TCP, TCP_CORK, [0],' $strace_out
53 fgrep 'SOL_TCP, TCP_CORK, [1],' $strace_out
56 t_begin "setup and start" && {
57 rainbows_setup $model 1 1
58 rtmpfiles strace_out
59 ed -s $unicorn_config <<EOF
60 ,s/^listen.*/listen "$listen", :tcp_nodelay => true, :tcp_nopush => true/
62 EOF
63 rainbows -D large-file-response.ru -c $unicorn_config -E none
64 rainbows_wait_start
67 t_begin "read worker pid" && {
68 worker_pid=$(curl -sSf http://$listen/pid)
69 kill -0 $worker_pid
72 t_begin "start strace on worker" && start_strace
74 t_begin "reading RSS uncorks" && {
75 curl -sSf http://$listen/rss >/dev/null
78 t_begin "restart strace on worker" && {
79 kill $strace_pid
80 wait
81 start_strace
84 t_begin "reading static file uncorks" && {
85 curl -sSf http://$listen/random_blob >/dev/null
86 check_TCP_CORK
89 t_begin "stop strace on worker" && {
90 kill $strace_pid
91 wait
94 t_begin "enable sendfile" && {
95 echo >> $unicorn_config 'require "sendfile"'
96 kill -HUP $rainbows_pid
97 test xSTART = x"$(cat $fifo)"
100 t_begin "reread worker pid" && {
101 worker_pid=$(curl -sSf http://$listen/pid)
102 kill -0 $worker_pid
105 t_begin "restart strace on the worker" && start_strace
107 t_begin "HTTP/1.x GET on static file with sendfile uncorks" && {
108 curl -sSf http://$listen/random_blob >/dev/null
109 check_TCP_CORK
112 t_begin "killing succeeds" && {
113 kill $strace_pid
114 wait
115 # dbgcat strace_out
116 kill $rainbows_pid
119 t_begin "check stderr" && check_stderr
121 t_done