2 # Copyright (c) 2009 Rainbows! developers
7 # sometimes we rely on http_proxy to avoid wasting bandwidth with Isolate
8 # and multiple Ruby versions
9 NO_PROXY
=${UNICORN_TEST_ADDR-127.0.0.1}
14 # defaulting to Base would unfortunately fail some concurrency tests
16 t_info
"model undefined, defaulting to $model"
21 RUBY_VERSION
=${RUBY_VERSION-$($RUBY -e 'puts RUBY_VERSION')}
22 t_pfx
=$PWD/trash
/$model.
$T-$RUBY_ENGINE-$RUBY_VERSION
28 test -x $PWD/bin
/unused_listen || die
"must be run in 't' directory"
30 # requires $1 and prints out the value of $2
34 if ! $RUBY -r$lib -e "puts $const" >/dev
/null
2>&1
36 t_info
"skipping $T since we don't have $lib"
41 # "date +%s" is not in POSIX, but in GNU, and FreeBSD 9.0 (possibly earlier)
43 $RUBY -e 'puts Time.now.to_i'
46 # "wc -l" outputs leading whitespace on *BSDs, filter it out for portability
48 wc -l |
tr -d '[:space:]'
51 # "wc -c" outputs leading whitespace on *BSDs, filter it out for portability
53 wc -c |
tr -d '[:space:]'
59 if test x
"$model" != x
"$i"
63 t_info
"skipping $T since it is not compatible with $model"
69 # given a list of variable names, create temporary files and assign
70 # the pathnames to those variables
82 T_RM_LIST
="$T_RM_LIST $_tmp"
86 T_RM_LIST
="$T_RM_LIST $_tmp"
90 T_OK_RM_LIST
="$T_OK_RM_LIST $_tmp"
100 sed -e "s/^/$id:/" < $_file
107 if grep -i Error
$_r_err
109 die
"Errors found in $_r_err"
110 elif grep SIGKILL
$_r_err
112 die
"SIGKILL found in $_r_err"
116 # rainbows_setup [ MODEL [ WORKER_CONNECTIONS ] ]
118 eval $
(unused_listen
)
119 rtmpfiles unicorn_config pid r_err r_out fifo tmp ok
120 cat > $unicorn_config <<EOF
126 after_fork do |server, worker|
127 # test script will block while reading from $fifo,
128 # so notify the script on the first worker we spawn
129 # by opening the FIFO
131 File.open("$fifo", "wb") { |fp| fp.syswrite "START" }
136 # set a higher default for tests since we run heavily-loaded
137 # boxes and sometimes sleep 1s in tests
140 echo " client_max_body_size nil"
144 test $# -ge 2 && echo " worker_connections $2"
147 echo " keepalive_timeout $3"
149 echo " keepalive_timeout $kato"
153 echo " keepalive_timeout $kato"
159 rainbows_wait_start
() {
160 # "cat $fifo" will block until the before_fork hook is called in
161 # the Unicorn config file
162 test xSTART
= x
"$(cat $fifo)"
163 rainbows_pid
=$
(cat $pid)
168 0) err_log
=$r_err status
=done ;;
169 1) err_log
=$1 status
=done ;;
170 2) err_log
=$1 status
=$2 ;;
172 while ! egrep '(done|error) reloading' < $err_log >/dev
/null
176 grep "$status reloading" $err_log >/dev
/null
185 while ! grep reaped
< $err_log >/dev
/null
192 _cmd
="$(which sha1sum 2>/dev/null || :)"
193 test -n "$_cmd" || _cmd
="$(which openssl 2>/dev/null || :) sha1"
194 test "$_cmd" != " sha1" || _cmd
="$(which gsha1sum 2>/dev/null || :)"
196 # last resort, see comments in sha1sum.rb for reasoning
197 test -n "$_cmd" || _cmd
=sha1sum.rb
198 expr "$($_cmd)" : '\([a-f0-9]\{40\}\)'
201 req_curl_chunked_upload_err_check
() {
203 curl
--version 2>/dev
/null |
awk '$1 == "curl" {
205 if ((v[1] < 7) || (v[1] == 7 && v[2] < 18))
211 t_info
"curl >= 7.18.0 required for $T"
220 t_info
"skipping $T since it's not Linux"
225 # we only allow splice on 2.6.32+
226 min
=32 uname_r
=$
(uname
-r)
229 sub
=$
(expr "$uname_r" : '2\.6\.\(.*\)$')
230 if test $sub -lt $min
232 t_info
"skipping $T (Linux $(uname_r < 2.6.$min)"
240 t_info
"skipping $T (Linux $uname_r < 2.6.$min)"
246 check_threaded_app_dispatch
() {
248 ThreadSpawn|ThreadPool
) ;;
249 RevThreadSpawn|RevThreadPool
) ;;
250 CoolioThreadSpawn|CoolioThreadPool
) ;;
251 XEpollThreadSpawn|XEpollThreadPool
) ;;
253 t_info
"$0 is only compatible with threaded app dispatch"
258 check_copy_stream
() {
259 case $RUBY_VERSION in
262 t_info
"skipping $T since it can't IO.copy_stream"
268 ThreadSpawn|WriterThreadSpawn|ThreadPool|WriterThreadPool|Base
) ;;
269 XEpollThreadSpawn|XEpollThreadPool
) ;;
271 t_info
"skipping $T since it doesn't use copy_stream"
278 Rev
) require_check
rev Rev
::VERSION
;;
279 Coolio
) require_check coolio Coolio
::VERSION
;;
280 Revactor
) require_check revactor Revactor
::VERSION
;;
281 EventMachine
) require_check eventmachine EventMachine
::VERSION
;;