From 2d3f12f0ca25ddfdec5b7d92f76489dcc1f26cf7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 30 Jun 2009 14:15:57 -0700 Subject: chunked_reader: Add test for chunk parse failure I'd honestly be more comfortable doing this in C (and possibly adapting the code from the libcurl internals since that code has been very well-tested). --- test/unit/test_chunked_reader.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/unit/test_chunked_reader.rb b/test/unit/test_chunked_reader.rb index ec5c68a..6a26c8f 100644 --- a/test/unit/test_chunked_reader.rb +++ b/test/unit/test_chunked_reader.rb @@ -1,5 +1,6 @@ require 'test/unit' require 'unicorn' +require 'unicorn/http11' require 'tempfile' require 'io/nonblock' require 'digest/sha1' @@ -18,6 +19,21 @@ class TestChunkedReader < Test::Unit::TestCase return if $$ != @start_pid @rd.close rescue nil @wr.close rescue nil + begin + Process.wait + rescue Errno::ECHILD + break + end while true + end + + def test_error + cr = bin_reader(@rd, "8\r\nasdfasdf\r\n8\r\nasdfasdfa#{'a' * 1024}") + a = nil + assert_nothing_raised { a = cr.readpartial(8192) } + assert_equal 'asdfasdf', a + assert_nothing_raised { a = cr.readpartial(8192) } + assert_equal 'asdfasdf', a + assert_raises(Unicorn::HttpParserError) { cr.readpartial(8192) } end def test_eof1 -- cgit v1.2.3-24-ge0c7