about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-16 23:57:31 +0000
committerEric Wong <normalperson@yhbt.net>2011-06-17 07:28:12 +0000
commit593deb92e8ebd4e77e482c567d97b6ee496ac378 (patch)
tree9162663c0e66d59225fe28d1f3133a8e118868af /t
parenta0c59adf71506b8808de276b1288a319424ee71a (diff)
downloadunicorn-593deb92e8ebd4e77e482c567d97b6ee496ac378.tar.gz
rescuing from SystemExit and exit()-ing again is ugly, but
changes made to lower stack depth positively affect _everyone_
so we'll tolerate some ugliness here.

We'll need to disable graceful exit for some tests, too...
Diffstat (limited to 't')
-rw-r--r--t/t0020-at_exit-handler.sh49
1 files changed, 49 insertions, 0 deletions
diff --git a/t/t0020-at_exit-handler.sh b/t/t0020-at_exit-handler.sh
new file mode 100644
index 0000000..fda14b5
--- /dev/null
+++ b/t/t0020-at_exit-handler.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+. ./test-lib.sh
+
+t_plan 5 "at_exit/END handlers work as expected"
+
+t_begin "setup and startup" && {
+        unicorn_setup
+        cat >> $unicorn_config <<EOF
+at_exit { \$stdout.syswrite("#{Process.pid} BOTH\\n") }
+END { \$stdout.syswrite("#{Process.pid} END BOTH\\n") }
+after_fork do |_,_|
+  at_exit { \$stdout.syswrite("#{Process.pid} WORKER ONLY\\n") }
+  END { \$stdout.syswrite("#{Process.pid} END WORKER ONLY\\n") }
+end
+EOF
+
+        unicorn -D pid.ru -c $unicorn_config
+        unicorn_wait_start
+}
+
+t_begin "read worker PID" && {
+        worker_pid=$(curl -sSf http://$listen/)
+        t_info "worker_pid=$worker_pid"
+}
+
+t_begin "issue graceful shutdown (SIGQUIT) and wait for termination" && {
+        kill -QUIT $unicorn_pid
+
+        while kill -0 $unicorn_pid >/dev/null 2>&1
+        do
+                sleep 1
+        done
+}
+
+t_begin "check stderr" && check_stderr
+
+dbgcat r_err
+dbgcat r_out
+
+t_begin "all at_exit handlers ran" && {
+        grep "$worker_pid BOTH" $r_out
+        grep "$unicorn_pid BOTH" $r_out
+        grep "$worker_pid END BOTH" $r_out
+        grep "$unicorn_pid END BOTH" $r_out
+        grep "$worker_pid WORKER ONLY" $r_out
+        grep "$worker_pid END WORKER ONLY" $r_out
+}
+
+t_done