about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2013-10-29 02:36:06 +0000
committerEric Wong <normalperson@yhbt.net>2013-10-29 02:42:26 +0000
commit01cef69c94033ecc2cb22b209f79deab2b0d55d6 (patch)
tree210f762f44bb0eaa6987d40c9600f0278d8f4f8a /test
parent66d4e85c5d8c5fa2874c6b5c73cf936e51e8537c (diff)
downloadyahns-01cef69c94033ecc2cb22b209f79deab2b0d55d6.tar.gz
We may also return HTTP 408 errors in this case.
Diffstat (limited to 'test')
-rw-r--r--test/test_input.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/test_input.rb b/test/test_input.rb
new file mode 100644
index 0000000..608ff23
--- /dev/null
+++ b/test/test_input.rb
@@ -0,0 +1,52 @@
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require_relative 'server_helper'
+require 'digest/md5'
+
+class TestInput < Testcase
+  ENV["N"].to_i > 1 and parallelize_me!
+  include ServerHelper
+  alias setup server_helper_setup
+  alias teardown server_helper_teardown
+
+  MD5 = lambda do |e|
+    input = e["rack.input"]
+    buf = ""
+    md5 = Digest::MD5.new
+    while input.read(16384, buf)
+      md5 << buf
+    end
+    body = md5.hexdigest
+    h = { "Content-Length" => body.size.to_s, "Content-Type" => 'text/plain' }
+    [ 200, h, [body] ]
+  end
+
+  def test_input_timeout_lazybuffer
+    stream_input_timeout(:lazy)
+  end
+
+  def test_input_timeout_nobuffer
+    stream_input_timeout(false)
+  end
+
+  def stream_input_timeout(ibtype)
+    err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
+    cfg.instance_eval do
+      GTL.synchronize do
+        app(:rack, MD5) do
+          listen "#{host}:#{port}"
+          input_buffering ibtype
+          client_timeout 1
+        end
+      end
+      stderr_path err.path
+    end
+    pid = mkserver(cfg)
+    c = get_tcp_client(host, port)
+    c.write "PUT / HTTP/1.1\r\nContent-Length: 666\r\n\r\n"
+    assert_equal c, c.wait(6)
+    Timeout.timeout(30) { assert_match %r{HTTP/1\.1 408 }, c.read }
+  ensure
+    quit_wait(pid)
+  end
+end