about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-28 08:40:12 +0000
committerEric Wong <normalperson@yhbt.net>2010-10-28 08:41:44 +0000
commit015635f877084cc05a9e6e4c1430c70279d0a04e (patch)
tree1570868d2ecd3d509dc2949005b3b922e973aab3
parentb06c6b3ac214bc598d499c994884113d5b106e90 (diff)
downloadrainbows-015635f877084cc05a9e6e4c1430c70279d0a04e.tar.gz
We need to ensure the old worker is really dead before sending
requests after reloading.
-rwxr-xr-xt/t0013-reload-bad-config.sh8
-rwxr-xr-xt/t0014-config-conflict.sh8
-rw-r--r--t/t0018-reload-restore-settings.sh23
-rw-r--r--t/test-lib.sh25
4 files changed, 33 insertions, 31 deletions
diff --git a/t/t0013-reload-bad-config.sh b/t/t0013-reload-bad-config.sh
index abe1d5e..9e10209 100755
--- a/t/t0013-reload-bad-config.sh
+++ b/t/t0013-reload-bad-config.sh
@@ -29,12 +29,8 @@ t_begin "introduce syntax error in rackup file" && {
 t_begin "reload signal succeeds" && {
         kill -HUP $rainbows_pid
         rainbows_wait_start
-        while ! egrep '(done|error) reloading' $r_err >/dev/null
-        do
-                sleep 1
-        done
-
-        grep 'error reloading' $r_err >/dev/null
+        wait_for_reload $r_err error
+        wait_for_reap
         > $r_err
 }
 
diff --git a/t/t0014-config-conflict.sh b/t/t0014-config-conflict.sh
index b91355d..b06c915 100755
--- a/t/t0014-config-conflict.sh
+++ b/t/t0014-config-conflict.sh
@@ -30,12 +30,8 @@ t_begin "modify rackup file" && {
 t_begin "reload signal succeeds" && {
         kill -HUP $rainbows_pid
         rainbows_wait_start
-        while ! egrep '(done|error) reloading' < $r_err >/dev/null
-        do
-                sleep 1
-        done
-
-        grep 'done reloading' $r_err >/dev/null
+        wait_for_reload
+        wait_for_reap
 }
 
 t_begin "hit with curl" && {
diff --git a/t/t0018-reload-restore-settings.sh b/t/t0018-reload-restore-settings.sh
index 24ee406..3a9471f 100644
--- a/t/t0018-reload-restore-settings.sh
+++ b/t/t0018-reload-restore-settings.sh
@@ -19,16 +19,8 @@ t_begin "clobber config and reload" && {
 stderr_path "$r_err"
 EOF
         kill -HUP $rainbows_pid
-        while ! egrep '(done|error) reloading' $r_err >/dev/null
-        do
-                sleep 1
-        done
-
-        grep 'done reloading' $r_err >/dev/null
-        while ! grep reaped $r_err >/dev/null
-        do
-                sleep 1
-        done
+        wait_for_reload
+        wait_for_reap
 }
 
 t_begin "HTTP request confirms we're on the default model" && {
@@ -41,15 +33,8 @@ t_begin "restore config and reload" && {
         > $r_err
         kill -HUP $rainbows_pid
         rainbows_wait_start
-        while ! egrep '(done|error) reloading' $r_err >/dev/null
-        do
-                sleep 1
-        done
-        while ! grep reaped $r_err >/dev/null
-        do
-                sleep 1
-        done
-        grep 'done reloading' $r_err >/dev/null
+        wait_for_reload
+        wait_for_reap
 }
 
 t_begin "HTTP request confirms we're back on the correct model" && {
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 0fea06b..4f9d4b1 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -148,6 +148,31 @@ rainbows_wait_start () {
         rainbows_pid=$(cat $pid)
 }
 
+wait_for_reload () {
+        case $# in
+        0) err_log=$r_err status=done ;;
+        1) err_log=$1 status=done ;;
+        2) err_log=$1 status=$2 ;;
+        esac
+        while ! egrep '(done|error) reloading' < $err_log >/dev/null
+        do
+                sleep 1
+        done
+        grep "$status reloading" $err_log >/dev/null
+}
+
+wait_for_reap () {
+        case $# in
+        0) err_log=$r_err ;;
+        1) err_log=$1 ;;
+        esac
+
+        while ! grep reaped < $err_log >/dev/null
+        do
+                sleep 1
+        done
+}
+
 rsha1 () {
         _cmd="$(which sha1sum 2>/dev/null || :)"
         test -n "$_cmd" || _cmd="$(which openssl 2>/dev/null || :) sha1"