about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-05-09 08:51:52 +0000
committerEric Wong <e@80x24.org>2015-05-09 09:28:12 +0000
commitbcdcea2e06a171e77a88770875ef6b91d7ab3ca3 (patch)
tree7fdedf02e9b6a08f37209408919c1eef9a67a216 /test
parent690d893af45bce8ac36f8fb739400ee0ff166d2e (diff)
downloadyahns-bcdcea2e06a171e77a88770875ef6b91d7ab3ca3.tar.gz
Rack::TempfileReaper was added in rack 1.6 to cleanup temporary
files.  Make Yahns::TmpIO ducktype-compatible and put it into
env['rack.tempfiles'] array so Rack::TempfileReaper may be used to
free up space used by temporary buffer files.

ref: commit 3bdf5481e49d76b4502c51e5bdd93f68bfd1f0b4 in unicorn
Diffstat (limited to 'test')
-rw-r--r--test/test_input.rb51
1 files changed, 50 insertions, 1 deletions
diff --git a/test/test_input.rb b/test/test_input.rb
index fe09a9a..63cf6ce 100644
--- a/test/test_input.rb
+++ b/test/test_input.rb
@@ -11,13 +11,28 @@ class TestInput < Testcase
 
   MD5 = lambda do |e|
     input = e["rack.input"]
+    tmp = e["rack.tempfiles"]
+    case input
+    when StringIO, Yahns::StreamInput
+      abort "unexpected tempfiles" if tmp && tmp.include?(input)
+    when Yahns::TmpIO
+      abort "rack.tempfiles missing" unless tmp
+      abort "rack.tempfiles missing rack.input" unless tmp.include?(input)
+    else
+      abort "unrecognized input type: #{input.class}"
+    end
+
     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' }
+    h = {
+      "Content-Length" => body.size.to_s,
+      "Content-Type" => 'text/plain',
+      "X-Input-Class" => input.class.to_s,
+    }
     [ 200, h, [body] ]
   end
 
@@ -63,6 +78,40 @@ class TestInput < Testcase
     [ host, port, pid ]
   end
 
+  def test_big_buffer_true
+    host, port, pid = input_server(MD5, true)
+
+    c = get_tcp_client(host, port)
+    buf = 'hello'
+    c.write "PUT / HTTP/1.0\r\nContent-Length: 5\r\n\r\n#{buf}"
+    head, body = c.read.split(/\r\n\r\n/)
+    assert_match %r{^X-Input-Class: StringIO\r\n}, head
+    assert_equal Digest::MD5.hexdigest(buf), body
+    c.close
+
+    c = get_tcp_client(host, port)
+    buf = 'hello' * 10000
+    c.write "PUT / HTTP/1.0\r\nContent-Length: 50000\r\n\r\n#{buf}"
+    head, body = c.read.split(/\r\n\r\n/)
+
+    # TODO: shouldn't need CapInput with known Content-Length...
+    assert_match %r{^X-Input-Class: Yahns::(CapInput|TmpIO)\r\n}, head
+    assert_equal Digest::MD5.hexdigest(buf), body
+    c.close
+
+    c = get_tcp_client(host, port)
+    c.write "PUT / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n"
+    c.write "Transfer-Encoding: chunked\r\n\r\n"
+    c.write "#{50000.to_s(16)}\r\n#{buf}\r\n0\r\n\r\n"
+    head, body = c.read.split(/\r\n\r\n/)
+    assert_match %r{^X-Input-Class: Yahns::CapInput\r\n}, head
+    assert_equal Digest::MD5.hexdigest(buf), body
+    c.close
+
+  ensure
+    quit_wait(pid)
+  end
+
   def test_read_negative_lazy; _read_neg(:lazy); end
   def test_read_negative_nobuffer; _read_neg(false); end