about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-05-03 16:16:48 -0700
committerEric Wong <normalperson@yhbt.net>2009-05-03 23:29:03 +0000
commitdf76b78d359f34a73ce407f40f594577e04b014b (patch)
treed7d75b2c850760b07b0e65aa0008b781133732f0 /test
parent895ae151c8703ebcd52becf5f2ca297d21274ef6 (diff)
downloadunicorn-df76b78d359f34a73ce407f40f594577e04b014b.tar.gz
Timeouts of less than 2 seconds are unsafe due to the lack of
subsecond resolution in most POSIX filesystems.  This is the
trade-off for using a low-complexity solution for timeouts.
Since this type of timeout is a last resort; 2 seconds is not
entirely unreasonable IMNSHO.  Additionally, timing out too
aggressively can put us in a fork loop and slow down the system.

Of course, the default is 60 seconds and most people do not
bother to change it.
Diffstat (limited to 'test')
-rw-r--r--test/unit/test_signals.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/unit/test_signals.rb b/test/unit/test_signals.rb
index bedce01..d8af285 100644
--- a/test/unit/test_signals.rb
+++ b/test/unit/test_signals.rb
@@ -37,6 +37,32 @@ class SignalsTest < Test::Unit::TestCase
     @server = nil
   end
 
+  def test_timeout_slow_response
+    pid = fork {
+      app = lambda { |env| sleep }
+      opts = @server_opts.merge(:timeout => 2)
+      redirect_test_io { HttpServer.new(app, opts).start.join }
+    }
+    t0 = Time.now
+    sock = nil
+    assert_nothing_raised do
+      sock = TCPSocket.new('127.0.0.1', @port)
+      sock.syswrite("GET / HTTP/1.0\r\n\r\n")
+    end
+
+    buf = nil
+    assert_raises(EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL,
+                  Errno::EBADF) do
+      buf = sock.sysread(4096)
+    end
+    diff = Time.now - t0
+    assert_nil buf
+    assert diff > 1.0, "diff was #{diff.inspect}"
+    assert diff < 60.0
+    ensure
+      Process.kill(:QUIT, pid) rescue nil
+  end
+
   def test_response_write
     app = lambda { |env|
       [ 200, { 'Content-Type' => 'text/plain', 'X-Pid' => Process.pid.to_s },