diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-04-27 03:47:46 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-04-27 15:21:56 -0700 |
commit | e9efec7fb79b0ff010664a4b85aaaddbf9a1e820 (patch) | |
tree | e718e18fb71510f2492c7b66a7aa0e5789f5a4de | |
parent | 889da081e87c0baf55ae45a3095e07184e6418d7 (diff) | |
download | unicorn-e9efec7fb79b0ff010664a4b85aaaddbf9a1e820.tar.gz |
It seems most applications use buffered IO#read instead of IO#sysread. So make sure our encoding is set correctly for buffered IO#read applications, too.
-rw-r--r-- | test/unit/test_upload.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/test/unit/test_upload.rb b/test/unit/test_upload.rb index b06dfdb..9ef3ed7 100644 --- a/test/unit/test_upload.rb +++ b/test/unit/test_upload.rb @@ -19,12 +19,28 @@ class UploadTest < Test::Unit::TestCase @sha1_app = lambda do |env| input = env['rack.input'] resp = { :pos => input.pos, :size => input.size, :class => input.class } + + # sysread @sha1.reset begin loop { @sha1.update(input.sysread(@bs)) } rescue EOFError end resp[:sha1] = @sha1.hexdigest + + # read + input.sysseek(0) if input.respond_to?(:sysseek) + input.rewind + @sha1.reset + loop { + buf = input.read(@bs) or break + @sha1.update(buf) + } + + if resp[:sha1] == @sha1.hexdigest + resp[:sysread_read_byte_match] = true + end + [ 200, @hdr.merge({'X-Resp' => resp.inspect}), [] ] end end @@ -218,6 +234,7 @@ class UploadTest < Test::Unit::TestCase assert $?.success?, 'curl ran OK' assert_match(%r!\b#{sha1}\b!, resp) assert_match(/Tempfile/, resp) + assert_match(/sysread_read_byte_match/, resp) # small StringIO path assert(system("dd", "if=#{@random.path}", "of=#{tmp.path}", @@ -233,6 +250,7 @@ class UploadTest < Test::Unit::TestCase assert $?.success?, 'curl ran OK' assert_match(%r!\b#{sha1}\b!, resp) assert_match(/StringIO/, resp) + assert_match(/sysread_read_byte_match/, resp) end private |