about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-20 00:54:17 +0000
committerEric Wong <normalperson@yhbt.net>2010-12-20 03:42:55 +0000
commit7e0dc42f7084e1719456a80b2e44049133c2e8b7 (patch)
treec9840f4eb56cc365664425b40b94978f43c40ed8
parent886e0a006d9e8e9c586beae28ed4dc5097064e90 (diff)
downloadrainbows-7e0dc42f7084e1719456a80b2e44049133c2e8b7.tar.gz
This was causing unrelated requests to get killed every
+timeout+ seconds, instead of only the ones that were
running too long.

Noticed-by: ghazel@gmail.com
ref:
http://mid.gmane.org/AANLkTi=7OhyTwkHsp_rXU7Gp1PokihiQ9bJigpO-BfN6@mail.gmail.com
-rw-r--r--lib/rainbows/thread_timeout.rb2
-rwxr-xr-xt/t9100-thread-timeout.sh22
-rwxr-xr-xt/t9101-thread-timeout-threshold.sh15
3 files changed, 25 insertions, 14 deletions
diff --git a/lib/rainbows/thread_timeout.rb b/lib/rainbows/thread_timeout.rb
index b9f6025..18f400b 100644
--- a/lib/rainbows/thread_timeout.rb
+++ b/lib/rainbows/thread_timeout.rb
@@ -90,7 +90,7 @@ class Rainbows::ThreadTimeout
         now = Time.now
         @lock.synchronize do
           @active.delete_if do |thread, time|
-            time >= now and thread.raise(ExecutionExpired).nil?
+            now >= time and thread.raise(ExecutionExpired).nil?
           end
         end
       end while true
diff --git a/t/t9100-thread-timeout.sh b/t/t9100-thread-timeout.sh
index ab46e5a..0f802dd 100755
--- a/t/t9100-thread-timeout.sh
+++ b/t/t9100-thread-timeout.sh
@@ -5,7 +5,7 @@ ThreadSpawn|ThreadPool|RevThreadSpawn|RevThreadPool) ;;
 *) t_info "$0 is only compatible with Thread*"; exit 0 ;;
 esac
 
-t_plan 5 "ThreadTimeout Rack middleware test for $model"
+t_plan 6 "ThreadTimeout Rack middleware test for $model"
 
 t_begin "configure and start" && {
         rtmpfiles curl_err
@@ -25,6 +25,26 @@ t_begin "sleepy request times out with 408" && {
         grep 408 $curl_err
 }
 
+t_begin "short requests do not timeout while making a long one" && {
+        rm -f $ok $curl_err
+        > $ok
+        curl -sSf http://$listen/2 2>$curl_err >/dev/null &
+        (
+                for i in $(awk </dev/null 'BEGIN{for(i=20;--i>=0;)print i}')
+                do
+                        curl -sSf http://$listen/0.1 >> $ok 2>&1 &
+                        test x"HI" = x"$(curl -sSf http://$listen/0.05)"
+                done
+                wait
+        )
+        test x"HI" = x"$(curl -sSf http://$listen/)"
+        wait
+        test -f $ok
+        test 20 -eq $(grep '^HI$' $ok | wc -l)
+        test x = x"$(grep -v '^HI$' $ok)"
+        grep 408 $curl_err
+}
+
 t_begin "kill server" && {
         kill $rainbows_pid
 }
diff --git a/t/t9101-thread-timeout-threshold.sh b/t/t9101-thread-timeout-threshold.sh
index 1979dba..99d3f98 100755
--- a/t/t9101-thread-timeout-threshold.sh
+++ b/t/t9101-thread-timeout-threshold.sh
@@ -30,25 +30,16 @@ t_begin "8 sleepy requests do not time out" && {
         test xHI = x"$(sort < $curl_out | uniq)"
 }
 
-t_begin "9 sleepy requests do time out" && {
+t_begin "9 sleepy requests, some time out" && {
         > $curl_err
         > $curl_out
         for i in 1 2 3 4 5 6 7 8 9
         do
-                rtmpfiles curl_err_$i
                 curl -sSf --no-buffer \
-                  http://$listen/3 2>> ${curl_err}_${i} >> $curl_out &
+                  http://$listen/3 2>> $curl_err >> $curl_out &
         done
         wait
-        if test -s $curl_out
-        then
-                dbgcat curl_out
-                die "$curl_out should be empty"
-        fi
-        for i in 1 2 3 4 5 6 7 8 9
-        do
-                grep 408 ${curl_err}_${i}
-        done
+        grep 408 $curl_err
 }
 
 t_begin "kill server" && {