about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-17 07:32:17 +0000
committerEric Wong <normalperson@yhbt.net>2011-06-17 07:32:17 +0000
commitfa7ce0a6a755cb71a30417478fb797ee7b8d94b5 (patch)
treeb2452700e1280af0bf61f4d66b7aebd8bf16d63f /t
parent593deb92e8ebd4e77e482c567d97b6ee496ac378 (diff)
downloadunicorn-fa7ce0a6a755cb71a30417478fb797ee7b8d94b5.tar.gz
"app error" is more correct, and consistent with Rainbows!
Diffstat (limited to 't')
-rw-r--r--t/broken-app.ru12
-rwxr-xr-xt/t0009-broken-app.sh56
2 files changed, 68 insertions, 0 deletions
diff --git a/t/broken-app.ru b/t/broken-app.ru
new file mode 100644
index 0000000..d05d7ab
--- /dev/null
+++ b/t/broken-app.ru
@@ -0,0 +1,12 @@
+# we do not want Rack::Lint or anything to protect us
+use Rack::ContentLength
+use Rack::ContentType, "text/plain"
+map "/" do
+  run lambda { |env| [ 200, {}, [ "OK\n" ] ] }
+end
+map "/raise" do
+  run lambda { |env| raise "BAD" }
+end
+map "/nil" do
+  run lambda { |env| nil }
+end
diff --git a/t/t0009-broken-app.sh b/t/t0009-broken-app.sh
new file mode 100755
index 0000000..895b178
--- /dev/null
+++ b/t/t0009-broken-app.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+. ./test-lib.sh
+
+t_plan 9 "graceful handling of broken apps"
+
+t_begin "setup and start" && {
+        unicorn_setup
+        unicorn -E none -D broken-app.ru -c $unicorn_config
+        unicorn_wait_start
+}
+
+t_begin "normal response is alright" && {
+        test xOK = x"$(curl -sSf http://$listen/)"
+}
+
+t_begin "app raised exception" && {
+        curl -sSf http://$listen/raise 2> $tmp || :
+        grep -F 500 $tmp
+        > $tmp
+}
+
+t_begin "app exception logged and backtrace not swallowed" && {
+        grep -F 'app error' $r_err
+        grep -A1 -F 'app error' $r_err | tail -1 | grep broken-app.ru:
+        dbgcat r_err
+        > $r_err
+}
+
+t_begin "trigger bad response" && {
+        curl -sSf http://$listen/nil 2> $tmp || :
+        grep -F 500 $tmp
+        > $tmp
+}
+
+t_begin "app exception logged" && {
+        grep -F 'app error' $r_err
+        > $r_err
+}
+
+t_begin "normal responses alright afterwards" && {
+        > $tmp
+        curl -sSf http://$listen/ >> $tmp &
+        curl -sSf http://$listen/ >> $tmp &
+        curl -sSf http://$listen/ >> $tmp &
+        curl -sSf http://$listen/ >> $tmp &
+        wait
+        test xOK = x$(sort < $tmp | uniq)
+}
+
+t_begin "teardown" && {
+        kill $unicorn_pid
+}
+
+t_begin "check stderr" && check_stderr
+
+t_done