about summary refs log tree commit homepage
path: root/test/unit/test_upload.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-04-23 18:35:26 -0700
committerEric Wong <normalperson@yhbt.net>2009-04-23 18:38:41 -0700
commit8ca2d34df19ed7802a59bdedb78e2261487c064c (patch)
tree652e4c7bccd646ec0c71ccec46916c1b00b871a2 /test/unit/test_upload.rb
parentf2e90a9f15efda1abc87cde00bb341fdf3368985 (diff)
downloadunicorn-8ca2d34df19ed7802a59bdedb78e2261487c064c.tar.gz
StringIO.new(partial_body) does not update the offset for new
writes.  So instead create the StringIO object and then syswrite
to it and try to follow the same code path used by large uploads
which use Tempfiles.
Diffstat (limited to 'test/unit/test_upload.rb')
-rw-r--r--test/unit/test_upload.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/unit/test_upload.rb b/test/unit/test_upload.rb
index 58058f1..86b6c6c 100644
--- a/test/unit/test_upload.rb
+++ b/test/unit/test_upload.rb
@@ -50,6 +50,29 @@ class UploadTest < Test::Unit::TestCase
     assert_equal @sha1.hexdigest, resp[:sha1]
   end
 
+  def test_put_trickle_small
+    @count, @bs = 2, 128
+    start_server(@sha1_app)
+    assert_equal 256, length
+    sock = TCPSocket.new(@addr, @port)
+    hdr = "PUT / HTTP/1.0\r\nContent-Length: #{length}\r\n\r\n"
+    @count.times do
+      buf = @random.sysread(@bs)
+      @sha1.update(buf)
+      hdr << buf
+      sock.syswrite(hdr)
+      hdr = ''
+      sleep 0.6
+    end
+    read = sock.read.split(/\r\n/)
+    assert_equal "HTTP/1.1 200 OK", read[0]
+    resp = eval(read.grep(/^X-Resp: /).first.sub!(/X-Resp: /, ''))
+    assert_equal length, resp[:size]
+    assert_equal 0, resp[:pos]
+    assert_equal @sha1.hexdigest, resp[:sha1]
+    assert_equal StringIO, resp[:class]
+  end
+
   def test_tempfile_unlinked
     spew_path = lambda do |env|
       if orig = env['HTTP_X_OLD_PATH']