about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-24 12:20:58 -0700
committerEric Wong <normalperson@yhbt.net>2009-10-24 12:20:58 -0700
commit2f8ed953decce975307a6c5b39330af816e184bc (patch)
tree07a56b46cf6aae765915d48cc1116c6ec20e7fee
parentbd8912c86fc3ef617e72e4cf59fb308dc06563ba (diff)
downloadrainbows-2f8ed953decce975307a6c5b39330af816e184bc.tar.gz
Instead of sleeping and waiting for a PID file to appear,
just use a named-pipe and block on it in the test scripts
since we know Unicorn won't attempt to fork until sockets
are already bound.
-rw-r--r--t/lib-async-response.sh16
-rw-r--r--t/lib-graceful.sh16
-rw-r--r--t/lib-input-trailer.sh14
-rw-r--r--t/lib-large-file-response.sh13
-rw-r--r--t/lib-parser-error.sh14
-rw-r--r--t/lib-rack-input-hammer.sh17
-rw-r--r--t/lib-reopen-logs.sh16
-rw-r--r--t/lib-simple-http.sh17
-rwxr-xr-xt/t9000-rack-app-pool.sh19
-rwxr-xr-xt/test-lib.sh40
10 files changed, 62 insertions, 120 deletions
diff --git a/t/lib-async-response.sh b/t/lib-async-response.sh
index 285751d..65c6056 100644
--- a/t/lib-async-response.sh
+++ b/t/lib-async-response.sh
@@ -1,20 +1,11 @@
 CONFIG_RU=${CONFIG_RU-'async-response.ru'}
 . ./test-lib.sh
 echo "async response for model=$model"
-eval $(unused_listen)
-rtmpfiles unicorn_config a b c r_err r_out pid curl_err
-
-cat > $unicorn_config <<EOF
-listen "$listen"
-stderr_path "$r_err"
-stdout_path "$r_out"
-pid "$pid"
-Rainbows! { use :$model }
-EOF
-
+rtmpfiles a b c curl_err
+rainbows_setup
 # can't load Rack::Lint here since it'll cause Rev to slurp
 rainbows -E none -D $CONFIG_RU -c $unicorn_config
-wait_for_pid $pid
+rainbows_wait_start
 
 t0=$(date +%s)
 ( curl --no-buffer -sSf http://$listen/ 2>> $curl_err | utee $a) &
@@ -23,7 +14,6 @@ t0=$(date +%s)
 wait
 t1=$(date +%s)
 
-rainbows_pid=$(cat $pid)
 kill -QUIT $rainbows_pid
 elapsed=$(( $t1 - $t0 ))
 echo "elapsed=$elapsed < 30"
diff --git a/t/lib-graceful.sh b/t/lib-graceful.sh
index 097bdbe..3bc3590 100644
--- a/t/lib-graceful.sh
+++ b/t/lib-graceful.sh
@@ -1,20 +1,10 @@
 . ./test-lib.sh
 echo "graceful test for model=$model"
 
-eval $(unused_listen)
-rtmpfiles unicorn_config curl_out pid r_err r_out fifo
-
-cat > $unicorn_config <<EOF
-listen "$listen"
-stderr_path "$r_err"
-stdout_path "$r_out"
-pid "$pid"
-Rainbows! { use :$model }
-EOF
-
+rtmpfiles curl_out
+rainbows_setup
 rainbows -D sleep.ru -c $unicorn_config
-wait_for_pid $pid
-rainbows_pid=$(cat $pid)
+rainbows_wait_start
 
 curl -sSfv -T- </dev/null http://$listen/5 > $curl_out 2> $fifo &
 
diff --git a/t/lib-input-trailer.sh b/t/lib-input-trailer.sh
index 072dd60..08331b1 100644
--- a/t/lib-input-trailer.sh
+++ b/t/lib-input-trailer.sh
@@ -2,19 +2,9 @@
 test -r random_blob || die "random_blob required, run with 'make $0'"
 echo "input trailer test model=$model"
 
-eval $(unused_listen)
-rtmpfiles unicorn_config tmp r_err r_out pid fifo ok
-
-cat > $unicorn_config <<EOF
-listen "$listen"
-pid "$pid"
-stderr_path "$r_err"
-stdout_path "$r_out"
-Rainbows! { use :$model }
-EOF
-
+rainbows_setup
 rainbows -D content-md5.ru -c $unicorn_config
-wait_for_pid $pid
+rainbows_wait_start
 
 echo "small blob"
 (
diff --git a/t/lib-large-file-response.sh b/t/lib-large-file-response.sh
index 9866982..4e387e0 100644
--- a/t/lib-large-file-response.sh
+++ b/t/lib-large-file-response.sh
@@ -6,20 +6,11 @@ then
         exit 0
 fi
 echo "large file response slurp avoidance for model=$model"
-eval $(unused_listen)
-rtmpfiles unicorn_config tmp r_err r_out pid ok fifo
-
-cat > $unicorn_config <<EOF
-listen "$listen"
-stderr_path "$r_err"
-stdout_path "$r_out"
-pid "$pid"
-Rainbows! { use :$model }
-EOF
 
+rainbows_setup
 # can't load Rack::Lint here since it'll cause Rev to slurp
 rainbows -E none -D large-file-response.ru -c $unicorn_config
-wait_for_pid $pid
+rainbows_wait_start
 
 random_blob_size=$(wc -c < random_blob)
 curl -v http://$listen/rss
diff --git a/t/lib-parser-error.sh b/t/lib-parser-error.sh
index d8805e3..4d4f63e 100644
--- a/t/lib-parser-error.sh
+++ b/t/lib-parser-error.sh
@@ -1,19 +1,9 @@
 . ./test-lib.sh
 echo "parser error test for model=$model"
 
-eval $(unused_listen)
-rtmpfiles unicorn_config pid r_err r_out tmp fifo ok
-
-cat > $unicorn_config <<EOF
-listen "$listen"
-pid "$pid"
-stderr_path "$r_err"
-stdout_path "$r_out"
-Rainbows! { use :$model }
-EOF
-
+rainbows_setup
 rainbows -D env.ru -c $unicorn_config
-wait_for_pid $pid
+rainbows_wait_start
 
 (
         printf 'GET / HTTP/1/1\r\nHost: example.com\r\n\r\n'
diff --git a/t/lib-rack-input-hammer.sh b/t/lib-rack-input-hammer.sh
index cb3f8c1..5bc3a58 100644
--- a/t/lib-rack-input-hammer.sh
+++ b/t/lib-rack-input-hammer.sh
@@ -2,21 +2,10 @@ nr_client=${nr_client-4}
 . ./test-lib.sh
 test -r random_blob || die "random_blob required, run with 'make $0'"
 
-eval $(unused_listen)
-rtmpfiles unicorn_config curl_out curl_err r_err r_out pid
-
-cat > $unicorn_config <<EOF
-listen "$listen"
-pid "$pid"
-stderr_path "$r_err"
-stdout_path "$r_out"
-Rainbows! do
-  use :$model
-end
-EOF
-
+rainbows_setup
+rtmpfiles curl_out curl_err
 rainbows -D sha1.ru -c $unicorn_config
-wait_for_pid $pid
+rainbows_wait_start
 
 start=$(date +%s)
 for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
diff --git a/t/lib-reopen-logs.sh b/t/lib-reopen-logs.sh
index 352a789..d295ba9 100644
--- a/t/lib-reopen-logs.sh
+++ b/t/lib-reopen-logs.sh
@@ -3,20 +3,10 @@
 nr_client=${nr_client-2}
 . ./test-lib.sh
 
-eval $(unused_listen)
-rtmpfiles unicorn_config curl_out curl_err pid r_err r_out r_rot
-
-
-cat > $unicorn_config <<EOF
-listen "$listen"
-pid "$pid"
-stderr_path "$r_err"
-stdout_path "$r_out"
-Rainbows! { use :$model }
-EOF
-
+rtmpfiles curl_out curl_err r_rot
+rainbows_setup
 rainbows -D sleep.ru -c $unicorn_config
-wait_for_pid $pid
+rainbows_wait_start
 
 # ensure our server is started and responding before signaling
 curl -sSf http://$listen/ >/dev/null
diff --git a/t/lib-simple-http.sh b/t/lib-simple-http.sh
index 410cc9a..235f4e3 100644
--- a/t/lib-simple-http.sh
+++ b/t/lib-simple-http.sh
@@ -6,22 +6,9 @@ echo "simple HTTP connection keepalive/pipelining tests for $model"
 tbase=$(expr "$T" : '^\(t....\)-').ru
 test -f "$tbase" || die "$tbase missing for $T"
 
-eval $(unused_listen)
-rtmpfiles unicorn_config pid r_err r_out tmp fifo ok
-
-cat > $unicorn_config <<EOF
-listen "$listen"
-pid "$pid"
-stderr_path "$r_err"
-stdout_path "$r_out"
-EOF
-if test x$model != xany
-then
-        echo "Rainbows! { use :$model }" >> $unicorn_config
-fi
-
+rainbows_setup
 rainbows -D $tbase -c $unicorn_config
-wait_for_pid $pid
+rainbows_wait_start
 
 echo "single request"
 curl -sSfv http://$listen/
diff --git a/t/t9000-rack-app-pool.sh b/t/t9000-rack-app-pool.sh
index 5530b9d..6c82ff8 100755
--- a/t/t9000-rack-app-pool.sh
+++ b/t/t9000-rack-app-pool.sh
@@ -1,25 +1,12 @@
 #!/bin/sh
 . ./test-lib.sh
 
-eval $(unused_listen)
-rtmpfiles unicorn_config pid r_err r_out curl_out curl_err
-
 nr_client=30
-
-cat > $unicorn_config <<EOF
-listen "$listen"
-pid "$pid"
-stderr_path "$r_err"
-stdout_path "$r_out"
-Rainbows! do
-  use :ThreadSpawn
-  worker_connections 50
-end
-EOF
-
+rtmpfiles curl_out curl_err
+rainbows_setup ThreadSpawn 50
 APP_POOL_SIZE=4
 APP_POOL_SIZE=$APP_POOL_SIZE rainbows -D t9000.ru -c $unicorn_config
-wait_for_pid $pid
+rainbows_wait_start
 
 start=$(date +%s)
 for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index b4ece30..d3815c4 100755
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -23,7 +23,7 @@ then
         t2???-thread-spawn-*.sh) model=ThreadSpawn ;;
         t3???-revactor-*.sh) model=Revactor ;;
         t4???-rev-*.sh) model=Rev ;;
-        *) model=any ;;
+        *) model=Base ;;
         esac
 fi
 
@@ -126,6 +126,44 @@ check_stderr () {
         fi
 }
 
+rainbows_setup () {
+        eval $(unused_listen)
+        rtmpfiles unicorn_config pid r_err r_out fifo tmp ok
+        cat > $unicorn_config <<EOF
+listen "$listen"
+pid "$pid"
+stderr_path "$r_err"
+stdout_path "$r_out"
+
+before_fork do |server, worker|
+  # test script will block while reading from $fifo,
+  # so notify the script on the first worker we spawn
+  # by opening the FIFO
+  if worker.nr == 0
+    File.open("$fifo", "wb").close
+  end
+end
+EOF
+        {
+                if test $# -ge 1
+                then
+                        echo 'Rainbows! do'
+                        echo "  use :$1"
+                        test $# -eq 2 && echo "  worker_connections $2"
+                        echo end
+                else
+                        echo "Rainbows! { use :$model }"
+                fi
+        } >> $unicorn_config
+}
+
+rainbows_wait_start () {
+        # "cat $fifo" will block until the before_fork hook is called in
+        # the Unicorn config file
+        test x = x"$(cat $fifo)"
+        rainbows_pid=$(cat $pid)
+}
+
 case $model in
 Rev) require_check rev Rev::VERSION ;;
 Revactor) require_check revactor Revactor::VERSION ;;