t0044: increase test reliability
[rainbows.git] / t / t0044-autopush.sh
blobbac97d7ed859a4b25e39cc905b9bef3f1c4f182a
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 Coolio CoolioThreadPool CoolioThreadSpawn
19 skip_models Revactor Rev RevThreadPool RevThreadSpawn
21 # not sure why, but we don't have time to care about Ruby 1.8 too much
22 case $RUBY_VERSION in
23 1.8.*) skip_models WriterThreadSpawn WriterThreadPool ;;
24 esac
26 t_plan 13 "Kgio autopush tests"
28 start_strace () {
29 # dbgcat strace_out
30 > $strace_out
31 sleep 1
32 strace -p $worker_pid -e '!futex' -f -o $strace_out &
33 strace_pid=$!
34 while ! test -s $strace_out; do sleep 1; done
37 check_TCP_CORK () {
38 nr=0
39 while test 2 -gt $(grep TCP_CORK $strace_out | wc -l)
41 nr=$(( $nr + 1 ))
42 if test $nr -gt 30
43 then
44 dbgcat strace_out
45 die "waited too long ($nr seconds) for TCP_CORK"
47 sleep 1
48 done
50 test 2 -eq $(grep TCP_CORK $strace_out | wc -l)
51 fgrep 'SOL_TCP, TCP_CORK, [0], 4) = 0' $strace_out
52 fgrep 'SOL_TCP, TCP_CORK, [1], 4) = 0' $strace_out
55 t_begin "setup and start" && {
56 rainbows_setup $model 1 1
57 rtmpfiles strace_out
58 ed -s $unicorn_config <<EOF
59 ,s/^listen.*/listen "$listen", :tcp_nodelay => true, :tcp_nopush => true/
61 EOF
62 rainbows -D large-file-response.ru -c $unicorn_config -E none
63 rainbows_wait_start
66 t_begin "read worker pid" && {
67 worker_pid=$(curl -sSf http://$listen/pid)
68 kill -0 $worker_pid
71 t_begin "start strace on worker" && start_strace
73 t_begin "reading RSS uncorks" && {
74 curl -sSf http://$listen/rss >/dev/null
77 t_begin "restart strace on worker" && {
78 kill $strace_pid
79 wait
80 start_strace
83 t_begin "reading static file uncorks" && {
84 curl -sSf http://$listen/random_blob >/dev/null
85 check_TCP_CORK
88 t_begin "stop strace on worker" && {
89 kill $strace_pid
90 wait
93 t_begin "enable sendfile" && {
94 echo >> $unicorn_config 'require "sendfile"'
95 kill -HUP $rainbows_pid
96 test xSTART = x"$(cat $fifo)"
99 t_begin "reread worker pid" && {
100 worker_pid=$(curl -sSf http://$listen/pid)
101 kill -0 $worker_pid
104 t_begin "restart strace on the worker" && start_strace
106 t_begin "HTTP/1.x GET on static file with sendfile uncorks" && {
107 curl -sSf http://$listen/random_blob >/dev/null
108 check_TCP_CORK
111 t_begin "killing succeeds" && {
112 kill $strace_pid
113 wait
114 # dbgcat strace_out
115 kill $rainbows_pid
118 t_begin "check stderr" && check_stderr
120 t_done