about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-10-11 20:54:05 -0700
committerEric Wong <normalperson@yhbt.net>2009-10-11 20:54:05 -0700
commita267b68ad921d115615abfc15de25a947e86fe38 (patch)
tree54f2aeb3d958a85ff31c89f1a569e5e78f0dda6c
parent90a03ee550741465ea43fd70e087851e17246fb6 (diff)
downloadrainbows-a267b68ad921d115615abfc15de25a947e86fe38.tar.gz
They were completely broken in the refactoring :x
-rw-r--r--lib/rainbows/base.rb2
-rw-r--r--lib/rainbows/thread_pool.rb2
-rw-r--r--lib/rainbows/thread_spawn.rb2
-rwxr-xr-xt/t1002-thread-pool-graceful.sh37
-rwxr-xr-xt/t2002-thread-spawn-graceful.sh37
5 files changed, 77 insertions, 3 deletions
diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb
index 8a38117..4d5fec1 100644
--- a/lib/rainbows/base.rb
+++ b/lib/rainbows/base.rb
@@ -81,7 +81,7 @@ module Rainbows
       logger.error e.backtrace.join("\n")
     end
 
-    def join_threads(threads)
+    def join_threads(threads, worker)
       logger.info "Joining threads..."
       threads.each { |thr| thr[:quit] = true }
       t0 = Time.now
diff --git a/lib/rainbows/thread_pool.rb b/lib/rainbows/thread_pool.rb
index 647436b..ba85051 100644
--- a/lib/rainbows/thread_pool.rb
+++ b/lib/rainbows/thread_pool.rb
@@ -30,7 +30,7 @@ module Rainbows
           thr.join(timeout) and break
         end
       end
-      join_threads(threads)
+      join_threads(pool, worker)
     end
 
     def new_worker_thread
diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb
index 77cc3f2..05068fc 100644
--- a/lib/rainbows/thread_spawn.rb
+++ b/lib/rainbows/thread_spawn.rb
@@ -50,7 +50,7 @@ module Rainbows
       rescue Object => e
         listen_loop_error(e) if LISTENERS.first
       end while LISTENERS.first && master_pid == Process.ppid
-      join_threads(threads.list)
+      join_threads(threads.list, worker)
     end
 
   end
diff --git a/t/t1002-thread-pool-graceful.sh b/t/t1002-thread-pool-graceful.sh
new file mode 100755
index 0000000..48f9363
--- /dev/null
+++ b/t/t1002-thread-pool-graceful.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+. ./test-lib.sh
+
+eval $(unused_listen)
+rtmpfiles unicorn_config curl_out curl_err pid r_err r_out
+nr_thread=10
+nr_client=10
+cat > $unicorn_config <<EOF
+listen "$listen"
+stderr_path "$r_err"
+stdout_path "$r_out"
+pid "$pid"
+Rainbows! do
+  use :ThreadPool
+  worker_connections $nr_thread
+end
+EOF
+
+rainbows -D sleep.ru -c $unicorn_config
+wait_for_pid $pid
+
+for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
+do
+        curl -sSf http://$listen/5 >> $curl_out 2>> $curl_err &
+done
+sleep 2
+kill -QUIT $(cat $pid)
+wait
+
+dbgcat r_err
+! test -s $curl_err
+test x"$(wc -l < $curl_out)" = x$nr_client
+nr=$(sort < $curl_out | uniq | wc -l)
+
+test "$nr" -eq 1
+test x$(sort < $curl_out | uniq) = xHello
+grep -v Error $r_err
diff --git a/t/t2002-thread-spawn-graceful.sh b/t/t2002-thread-spawn-graceful.sh
new file mode 100755
index 0000000..1eb1047
--- /dev/null
+++ b/t/t2002-thread-spawn-graceful.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+. ./test-lib.sh
+
+eval $(unused_listen)
+rtmpfiles unicorn_config curl_out curl_err pid r_err r_out
+nr_thread=10
+nr_client=10
+cat > $unicorn_config <<EOF
+listen "$listen"
+stderr_path "$r_err"
+stdout_path "$r_out"
+pid "$pid"
+Rainbows! do
+  use :ThreadSpawn
+  worker_connections $nr_thread
+end
+EOF
+
+rainbows -D sleep.ru -c $unicorn_config
+wait_for_pid $pid
+
+for i in $(awk "BEGIN{for(i=0;i<$nr_client;++i) print i}" </dev/null)
+do
+        curl -sSf http://$listen/5 >> $curl_out 2>> $curl_err &
+done
+sleep 2
+kill -QUIT $(cat $pid)
+wait
+
+dbgcat r_err
+! test -s $curl_err
+test x"$(wc -l < $curl_out)" = x$nr_client
+nr=$(sort < $curl_out | uniq | wc -l)
+
+test "$nr" -eq 1
+test x$(sort < $curl_out | uniq) = xHello
+grep -v Error $r_err