never_block: simplify and split out code
[rainbows.git] / t / t0015-working_directory.sh
blob84fe4cc3893c8202179091bcd357e13b8a727cf6
1 #!/bin/sh
2 if test -n "$RBX_SKIP"
3 then
4 echo "$0 is broken under Rubinius for now"
5 exit 0
6 fi
7 . ./test-lib.sh
9 t_plan 5 "config.ru inside alt working_directory"
11 t_begin "setup and start" && {
12 rainbows_setup
13 rtmpfiles unicorn_config_tmp
14 rm -rf $t_pfx.app
15 mkdir $t_pfx.app
17 cat > $t_pfx.app/config.ru <<EOF
18 #\--daemonize --listen $listen
19 use Rack::ContentLength
20 use Rack::ContentType, "text/plain"
21 run lambda { |env| [ 200, {}, [ "#{\$master_ppid}\\n" ] ] }
22 EOF
23 # we have --host/--port in config.ru instead
24 grep -v ^listen $unicorn_config > $unicorn_config_tmp
26 # the whole point of this exercise
27 echo "working_directory '$t_pfx.app'" >> $unicorn_config_tmp
29 # allows ppid to be 1 in before_fork
30 echo "preload_app true" >> $unicorn_config_tmp
31 cat >> $unicorn_config_tmp <<\EOF
32 before_fork do |server,worker|
33 $master_ppid = Process.ppid # should be zero to detect daemonization
34 end
35 EOF
37 mv $unicorn_config_tmp $unicorn_config
39 # rely on --daemonize switch, no & or -D
40 rainbows -c $unicorn_config
41 rainbows_wait_start
44 t_begin "hit with curl" && {
45 body=$(curl -sSf http://$listen/)
48 t_begin "killing succeeds" && {
49 kill $rainbows_pid
52 t_begin "response body ppid == 1 (daemonized)" && {
53 test "$body" -eq 1
56 t_begin "cleanup working directory" && {
57 rm -r $t_pfx.app
60 t_done