about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-02-17 19:24:09 -0800
committerEric Wong <normalperson@yhbt.net>2010-02-18 13:34:13 -0800
commit8963e87841501c8e79b8434f8887e0d3a78b580c (patch)
tree0c85fc9b6ed9c1c06c70ab4115e87c7c836ac9e8 /t
parentae0c39e09b27e953f41b2714c5d194a9e9a00da2 (diff)
downloadunicorn-8963e87841501c8e79b8434f8887e0d3a78b580c.tar.gz
If preload_app is true and Unicorn is HUP-ed with a bad
config.ru, then it would be possible to have Unicorn in a bad
state and constantly throw 500 errors.

We now detect syntax and load errors since they're likely to
appear in modified Rackup files, and will restore the original
app if reloading failed.
Diffstat (limited to 't')
-rwxr-xr-xt/t0001-reload-bad-config.sh52
1 files changed, 52 insertions, 0 deletions
diff --git a/t/t0001-reload-bad-config.sh b/t/t0001-reload-bad-config.sh
new file mode 100755
index 0000000..e1393ae
--- /dev/null
+++ b/t/t0001-reload-bad-config.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+. ./test-lib.sh
+t_plan 7 "reload config.ru error with preload_app true"
+
+t_begin "setup and start" && {
+        unicorn_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
+        unicorn -D -c $unicorn_config $ru
+        unicorn_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 $unicorn_pid
+        while ! egrep '(done|error) reloading' $r_err >/dev/null
+        do
+                sleep 1
+        done
+
+        grep 'error 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 $unicorn_pid
+}
+
+t_begin "check stderr" && {
+        check_stderr
+}
+
+t_done