diff options
-rw-r--r-- | bin/rainbows | 34 | ||||
-rw-r--r-- | rainbows.gemspec | 2 | ||||
-rwxr-xr-x | t/t0013-reload-bad-config.sh | 54 | ||||
-rwxr-xr-x | t/t0014-config-conflict.sh | 50 |
4 files changed, 107 insertions, 33 deletions
diff --git a/bin/rainbows b/bin/rainbows index 77059ef..ba7ee7f 100644 --- a/bin/rainbows +++ b/bin/rainbows @@ -122,37 +122,7 @@ end require 'pp' if $DEBUG -app = lambda do || - # require Rack as late as possible in case $LOAD_PATH is modified - # in config.ru or command-line - inner_app = case config - when /\.ru$/ - raw = File.open(config, "rb") { |fp| fp.sysread(fp.stat.size) } - raw.sub!(/^__END__\n.*/, '') - eval("Rack::Builder.new {(#{raw}\n)}.to_app", nil, config) - else - require config - Object.const_get(File.basename(config, '.rb').capitalize) - end - pp({ :inner_app => inner_app }) if $DEBUG - case ENV["RACK_ENV"] - when "development" - Rack::Builder.new do - use Rack::CommonLogger, $stderr - use Rack::ShowExceptions - use Rack::Lint - run inner_app - end.to_app - when "deployment" - Rack::Builder.new do - use Rack::CommonLogger, $stderr - run inner_app - end.to_app - else - inner_app - end -end - +app = Unicorn.builder(config) listeners << "#{host}:#{port}" if set_listener if $DEBUG @@ -163,5 +133,5 @@ if $DEBUG }) end -Unicorn::Launcher.daemonize! if daemonize +Unicorn::Launcher.daemonize!(options) if daemonize Rainbows.run(app, options) diff --git a/rainbows.gemspec b/rainbows.gemspec index fc6be20..0fda618 100644 --- a/rainbows.gemspec +++ b/rainbows.gemspec @@ -43,7 +43,7 @@ Gem::Specification.new do |s| # we need Unicorn for the HTTP parser and process management # The HTTP parser in Unicorn < 0.96.1 did not use the Ruby # API correctly and resulted in a memory leak - s.add_dependency(%q<unicorn>, ["~> 0.96.1", "< 0.97.0"]) + s.add_dependency(%q<unicorn>, ["~> 0.97.0"]) # Unicorn already depends on Rack # s.add_dependency(%q<rack>) diff --git a/t/t0013-reload-bad-config.sh b/t/t0013-reload-bad-config.sh new file mode 100755 index 0000000..abe1d5e --- /dev/null +++ b/t/t0013-reload-bad-config.sh @@ -0,0 +1,54 @@ +#!/bin/sh +. ./test-lib.sh +t_plan 7 "reload config.ru error with preload_app true" + +t_begin "setup and start" && { + rainbows_setup + rtmpfiles ru + + cat > $ru <<\EOF +use Rack::ContentLength +use Rack::ContentType, "text/plain" +x = { "hello" => "world" } +run lambda { |env| [ 200, {}, [ x.inspect << "\n" ] ] } +EOF + echo 'preload_app true' >> $unicorn_config + rainbows -D -c $unicorn_config $ru + rainbows_wait_start +} + +t_begin "hit with curl" && { + out=$(curl -sSf http://$listen/) + test x"$out" = x'{"hello"=>"world"}' +} + +t_begin "introduce syntax error in rackup file" && { + echo '...' >> $ru +} + +t_begin "reload signal succeeds" && { + kill -HUP $rainbows_pid + rainbows_wait_start + while ! egrep '(done|error) reloading' $r_err >/dev/null + do + sleep 1 + done + + grep 'error reloading' $r_err >/dev/null + > $r_err +} + +t_begin "hit with curl" && { + out=$(curl -sSf http://$listen/) + test x"$out" = x'{"hello"=>"world"}' +} + +t_begin "killing succeeds" && { + kill $rainbows_pid +} + +t_begin "check stderr" && { + check_stderr +} + +t_done diff --git a/t/t0014-config-conflict.sh b/t/t0014-config-conflict.sh new file mode 100755 index 0000000..b91355d --- /dev/null +++ b/t/t0014-config-conflict.sh @@ -0,0 +1,50 @@ +#!/bin/sh +. ./test-lib.sh +t_plan 6 "config variables conflict with preload_app" + +t_begin "setup and start" && { + rainbows_setup + rtmpfiles ru rutmp + + cat > $ru <<\EOF +use Rack::ContentLength +use Rack::ContentType, "text/plain" +config = ru = { "hello" => "world" } +run lambda { |env| [ 200, {}, [ ru.inspect << "\n" ] ] } +EOF + echo 'preload_app true' >> $unicorn_config + rainbows -D -c $unicorn_config $ru + rainbows_wait_start +} + +t_begin "hit with curl" && { + out=$(curl -sSf http://$listen/) + test x"$out" = x'{"hello"=>"world"}' +} + +t_begin "modify rackup file" && { + sed -e 's/world/WORLD/' < $ru > $rutmp + mv $rutmp $ru +} + +t_begin "reload signal succeeds" && { + kill -HUP $rainbows_pid + rainbows_wait_start + while ! egrep '(done|error) reloading' < $r_err >/dev/null + do + sleep 1 + done + + grep 'done reloading' $r_err >/dev/null +} + +t_begin "hit with curl" && { + out=$(curl -sSf http://$listen/) + test x"$out" = x'{"hello"=>"WORLD"}' +} + +t_begin "killing succeeds" && { + kill $rainbows_pid +} + +t_done |