about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-04 18:39:19 -0700
committerEric Wong <normalperson@yhbt.net>2009-10-04 19:18:23 -0700
commit9f11d1cec1975f4dcf35c68538243a44a629ed62 (patch)
tree45f4bb93272674cbe64b99ae5eb79801dc93d5be /t
parent903766ba0d278cb55d08e072c4c96c1d7f0dee8d (diff)
downloadrainbows-9f11d1cec1975f4dcf35c68538243a44a629ed62.tar.gz
This is somewhat like the original model found in Mongrel,
except we refuse to accept() connections unless we have slots
available.   Even though we support multiple listen sockets, we
only accept() synchronously to simplify processing and to avoid
having to synchronize ThreadGroup management.
Diffstat (limited to 't')
-rwxr-xr-xt/t2000-thread-spawn-basic.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/t/t2000-thread-spawn-basic.sh b/t/t2000-thread-spawn-basic.sh
new file mode 100755
index 0000000..ff48cb5
--- /dev/null
+++ b/t/t2000-thread-spawn-basic.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+. ./test-lib.sh
+
+eval $(unused_listen)
+config_ru=$(mktemp -t rainbows.$$.XXXXXXXX.config.ru)
+unicorn_config=$(mktemp -t rainbows.$$.XXXXXXXX.unicorn.rb)
+curl_out=$(mktemp -t rainbows.$$.XXXXXXXX.curl.out)
+curl_err=$(mktemp -t rainbows.$$.XXXXXXXX.curl.err)
+pid=$(mktemp -t rainbows.$$.XXXXXXXX.pid)
+TEST_RM_LIST="$TEST_RM_LIST $config_ru $unicorn_config $lock_path"
+TEST_RM_LIST="$TEST_RM_LIST $curl_out $curl_err"
+
+cat > $config_ru <<\EOF
+use Rack::ContentLength
+use Rack::ContentType
+run lambda { |env|
+  sleep 1
+  [ 200, {}, [ Thread.current.inspect << "\n" ] ]
+}
+EOF
+
+nr_client=30
+nr_thread=10
+
+cat > $unicorn_config <<EOF
+listen "$listen"
+pid "$pid"
+Rainbows! do
+  use :ThreadSpawn
+  worker_connections $nr_thread
+end
+EOF
+
+rainbows -D $config_ru -c $unicorn_config
+wait_for_pid $pid
+
+start=$(date +%s)
+for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
+do
+        ( curl -sSf http://$listen/$i >> $curl_out 2>> $curl_err ) &
+done
+wait
+echo elapsed=$(( $(date +%s) - $start ))
+
+kill $(cat $pid)
+
+! test -s $curl_err
+test x"$(wc -l < $curl_out)" = x$nr_client
+nr=$(sort < $curl_out | uniq | wc -l)
+test "$nr" -eq $nr_client