diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-10-04 16:38:08 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-10-04 18:38:32 -0700 |
commit | 903766ba0d278cb55d08e072c4c96c1d7f0dee8d (patch) | |
tree | 3f29a3aab6452c304043816c7c1c3c76f3009d8a /t/t1000-thread-pool-basic.sh | |
parent | 756c060f2992d35e30249688f1cfab8de9b4dfc1 (diff) | |
download | rainbows-903766ba0d278cb55d08e072c4c96c1d7f0dee8d.tar.gz |
I'd rather write shell scripts in shell than shell scripts in Ruby like was done with Unicorn. We're a *nix-only project so we'll embrace *nix tools to their fullest extent and as a pleasant side-effect these test cases are immune to internal API changes.
Diffstat (limited to 't/t1000-thread-pool-basic.sh')
-rwxr-xr-x | t/t1000-thread-pool-basic.sh | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/t/t1000-thread-pool-basic.sh b/t/t1000-thread-pool-basic.sh new file mode 100755 index 0000000..109f5ae --- /dev/null +++ b/t/t1000-thread-pool-basic.sh @@ -0,0 +1,53 @@ +#!/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 :ThreadPool + 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" -le $nr_thread +test "$nr" -gt 1 |