about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-04-07 22:08:43 +0000
committerEric Wong <e@80x24.org>2015-04-07 22:09:23 +0000
commitd5400442b931e31f0edf7d184b18845e728f867d (patch)
tree106c50ef2ec9e2c99d70ccfcffb01547b59f69ea /test
parent76cc538fd8962eb380e8980a78d59b2133880196 (diff)
downloadyahns-d5400442b931e31f0edf7d184b18845e728f867d.tar.gz
kgio_writev returns nil on success instead of the number of bytes
written, so we must manually calculate the number of bytes written
intead :x

This is triggerable when sending giant chunked responses.
Diffstat (limited to 'test')
-rw-r--r--test/test_proxy_pass.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/test_proxy_pass.rb b/test/test_proxy_pass.rb
index f5ae12f..e4e97d1 100644
--- a/test/test_proxy_pass.rb
+++ b/test/test_proxy_pass.rb
@@ -2,6 +2,7 @@
 # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
 require_relative 'server_helper'
 require 'json'
+require 'digest'
 
 class TestProxyPass < Testcase
   ENV["N"].to_i > 1 and parallelize_me!
@@ -17,6 +18,8 @@ class TestProxyPass < Testcase
   BIG_HEADER = [%w(Content-Type text/plain), %W(Content-Length #{OMFG.size})]
   3000.times { |i| BIG_HEADER << %W(X-#{i} BIG-HEADER!!!!!!!!!!!!!!) }
   BIG_HEADER.freeze
+  STR4 = 'abcd' * (256 * 1024)
+  NCHUNK = 50
 
   class ProxiedApp
     def call(env)
@@ -27,6 +30,19 @@ class TestProxyPass < Testcase
         when '/giant-body'
           h = [ %W(Content-Length #{OMFG.size}), %w(Content-Type text/plain) ]
           [ 200, h, [ OMFG ] ]
+        when '/giant-chunky-body'
+          h = [ %w(content-type text/pain), %w(transfer-encoding chunked) ]
+          chunky = Object.new
+          def chunky.each
+            head = STR4.size.to_s(16) << "\r\n"
+            NCHUNK.times do
+              yield head
+              yield STR4
+              yield "\r\n".freeze
+            end
+            yield "0\r\n\r\n"
+          end
+          [ 200, h, chunky ]
         when '/big-headers'
           [ 200, BIG_HEADER, [ OMFG ] ]
         when '/oversize-headers'
@@ -281,6 +297,17 @@ class TestProxyPass < Testcase
       assert_equal 200, res.code.to_i
       assert_equal OMFG, res.body
 
+      # giant chunky body
+      sha1 = Digest::SHA1.new
+      http.request(Net::HTTP::Get.new('/giant-chunky-body')) do |response|
+        response.read_body do |chunk|
+          sha1.update(chunk)
+        end
+      end
+      check = Digest::SHA1.new
+      NCHUNK.times { check.update(STR4) }
+      assert_equal check.hexdigest, sha1.hexdigest
+
       # giant PUT content-length
       req = Net::HTTP::Put.new('/')
       req.body_stream = StringIO.new(OMFG)