about summary refs log tree commit homepage
path: root/t/t0007-worker-follows-master-to-death.sh
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-11-06 19:45:17 -0800
committerEric Wong <normalperson@yhbt.net>2009-11-06 19:45:17 -0800
commit1a9a718a3f9a5b582a4a339a9bb9249c2ca392d7 (patch)
tree0c95f2d8fc4de8542f7716832800614e1e7a8872 /t/t0007-worker-follows-master-to-death.sh
parente1dcadef6ca242e36e99aab19e3e040bf01070f9 (diff)
downloadrainbows-1a9a718a3f9a5b582a4a339a9bb9249c2ca392d7.tar.gz
It turns out neither the EventMachine and Rev classes
checked for master death in its heartbeat mechanism.
Since we managed to forget the same thing twice, we
now have a test case for it and also centralized the
code to remove duplication.
Diffstat (limited to 't/t0007-worker-follows-master-to-death.sh')
-rwxr-xr-xt/t0007-worker-follows-master-to-death.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/t/t0007-worker-follows-master-to-death.sh b/t/t0007-worker-follows-master-to-death.sh
new file mode 100755
index 0000000..ac40277
--- /dev/null
+++ b/t/t0007-worker-follows-master-to-death.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+. ./test-lib.sh
+t_plan 7 "ensure worker follows master to death"
+
+t_begin "setup" && {
+        rtmpfiles curl_err curl_out
+        rainbows_setup
+        echo timeout 3 >> $unicorn_config
+        rainbows -D -c $unicorn_config worker-follows-master-to-death.ru
+        rainbows_wait_start
+}
+
+t_begin "read worker PID" && {
+        worker_pid=$(curl -sSf http://$listen/pid)
+        t_info "worker_pid=$worker_pid"
+}
+
+t_begin "start a long sleeping request" && {
+        curl -sSfv -T- </dev/null http://$listen/sleep/2 >$curl_out 2> $fifo &
+        curl_pid=$!
+        t_info "curl_pid=$curl_pid"
+}
+
+t_begin "nuke the master once we're connected" && {
+        awk -v rainbows_pid=$rainbows_pid '
+{ print $0 }
+/100 Continue/ {
+        print "awk: sending SIGKILL to", rainbows_pid
+        system("kill -9 "rainbows_pid)
+}' < $fifo > $curl_err
+        wait
+}
+
+t_begin "worker is no longer running" && {
+        sleep 6
+        kill -0 $worker_pid 2> $tmp && false
+        test -s $tmp
+}
+
+t_begin "sleepy curl request is no longer running" && {
+        kill -0 $curl_pid 2> $tmp && false
+        test -s $tmp
+}
+
+t_begin "sleepy curl request completed gracefully" && {
+        test x$(cat $curl_out) = x$worker_pid
+        dbgcat curl_err
+}
+
+t_done