summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-16 23:11:28 +0000
committerEric Wong <normalperson@yhbt.net>2011-06-16 23:14:04 +0000
commit95f543a9583e58c56b1c480df84b4b88e6669403 (patch)
tree63e41e454e7001ed213ea6f5520f36ab6d3ea579
parent4beeb52b1c52ea4486dea13cebe2a8438a9f2139 (diff)
Just in case we break anything
-rw-r--r--t/heartbeat-timeout.ru12
-rwxr-xr-xt/t0004-heartbeat-timeout.sh69
2 files changed, 81 insertions, 0 deletions
diff --git a/t/heartbeat-timeout.ru b/t/heartbeat-timeout.ru
new file mode 100644
index 0000000..d9904e8
--- /dev/null
+++ b/t/heartbeat-timeout.ru
@@ -0,0 +1,12 @@
+use Rack::ContentLength
+headers = { 'Content-Type' => 'text/plain' }
+run lambda { |env|
+  case env['PATH_INFO']
+  when "/block-forever"
+    Process.kill(:STOP, $$)
+    sleep # in case STOP signal is not received in time
+    [ 500, headers, [ "Should never get here\n" ] ]
+  else
+    [ 200, headers, [ "#$$\n" ] ]
+  end
+}
diff --git a/t/t0004-heartbeat-timeout.sh b/t/t0004-heartbeat-timeout.sh
new file mode 100755
index 0000000..bf73ebe
--- /dev/null
+++ b/t/t0004-heartbeat-timeout.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+. ./test-lib.sh
+
+t_plan 11 "heartbeat/timeout test"
+
+t_begin "setup and startup" && {
+        unicorn_setup
+        echo timeout 3 >> $unicorn_config
+        echo preload_app true >> $unicorn_config
+        unicorn -D heartbeat-timeout.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 "sleep for a bit, ensure worker PID does not change" && {
+        sleep 4
+        test $(curl -sSf http://$listen/) -eq $worker_pid
+}
+
+t_begin "block the worker process to force it to die" && {
+        rm $ok
+        t0=$(date +%s)
+        err="$(curl -sSf http://$listen/block-forever 2>&1 || > $ok)"
+        t1=$(date +%s)
+        elapsed=$(($t1 - $t0))
+        t_info "elapsed=$elapsed err=$err"
+        test x"$err" != x"Should never get here"
+        test x"$err" != x"$worker_pid"
+}
+
+t_begin "ensure worker was killed" && {
+        test -e $ok
+        test 1 -eq $(grep timeout $r_err | grep killing | wc -l)
+}
+
+t_begin "ensure timeout took at least 3 seconds" && {
+        test $elapsed -ge 3
+}
+
+t_begin "we get a fresh new worker process" && {
+        new_worker_pid=$(curl -sSf http://$listen/)
+        test $new_worker_pid -ne $worker_pid
+}
+
+t_begin "truncate the server error log" && {
+        > $r_err
+}
+
+t_begin "SIGSTOP and SIGCONT on unicorn master does not kill worker" && {
+        kill -STOP $unicorn_pid
+        sleep 4
+        kill -CONT $unicorn_pid
+        sleep 2
+        test $new_worker_pid -eq $(curl -sSf http://$listen/)
+}
+
+t_begin "stop server" && {
+        kill -QUIT $unicorn_pid
+}
+
+t_begin "check stderr" && check_stderr
+
+dbgcat r_err
+
+t_done