test/test_response.rb in kcar-0.3.0 vs test/test_response.rb in kcar-0.3.1
- old
+ new
@@ -483,11 +483,11 @@
assert status.success?
body.close
assert ! @c.closed?
end
- def test_rack_preserve_chunk_ary_no_keepalive
+ def test_rack_preserve_chunk_no_keepalive
pid = fork do
@s << "HTTP/1.1 200 OK\r\n"
@s << "Connection: close\r\n"
@s << "Trailer: Foo\r\n"
@s << "Transfer-Encoding: chunked\r\n\r\n"
@@ -499,13 +499,38 @@
assert_kind_of Array, headers
assert_equal status, "200 OK"
tmp = []
assert ! body.parser.keepalive?
assert_nothing_raised { body.each { |chunk| tmp << chunk.dup } }
- assert_equal ["5\r\nhello\r\n0\r\nFoo: bar\r\n\r\n"], tmp
+ assert_equal "5\r\nhello\r\n0\r\nFoo: bar\r\n\r\n", tmp.join
_, status = Process.waitpid2(pid)
assert status.success?
body.close
assert @c.closed?
end
+ def test_rack_preserve_chunk_no_keepalive
+ s = "HTTP/1.1 200 OK\r\n"
+ s << "Connection: close\r\n"
+ s << "Content-Length: 666\r\n"
+ s << "\r\n"
+ s << "hello"
+ @s.write(s)
+ @response = Kcar::Response.new(@c, [])
+ status, headers, body = @response.rack
+ assert_kind_of Array, headers
+ assert_equal status, "200 OK"
+ tmp = []
+ assert ! body.parser.keepalive?
+
+ closer = Thread.new do
+ Thread.pass until tmp[0]
+ @s.close
+ end
+ assert_raises(EOFError) {
+ body.each { |chunk| tmp << chunk.dup }
+ }
+ assert_nil @c.close
+ assert_equal "hello", tmp[0]
+ assert_nil closer.value
+ end
end