diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/exec/test_exec.rb | 2 | ||||
-rw-r--r-- | test/unit/test_http_parser_ng.rb | 38 | ||||
-rw-r--r-- | test/unit/test_request.rb | 12 | ||||
-rw-r--r-- | test/unit/test_response.rb | 23 | ||||
-rw-r--r-- | test/unit/test_signals.rb | 2 | ||||
-rw-r--r-- | test/unit/test_tee_input.rb | 39 |
6 files changed, 84 insertions, 32 deletions
diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb index 1d24ca3..581d5d5 100644 --- a/test/exec/test_exec.rb +++ b/test/exec/test_exec.rb @@ -614,7 +614,7 @@ EOF results = retry_hit(["http://#{@addr}:#{@port}/"]) assert_equal String, results[0].class assert_shutdown(pid) - end unless ENV['RBX_SKIP'] + end def test_config_ru_alt_path config_path = "#{@tmpdir}/foo.ru" diff --git a/test/unit/test_http_parser_ng.rb b/test/unit/test_http_parser_ng.rb index cb30f32..65b843e 100644 --- a/test/unit/test_http_parser_ng.rb +++ b/test/unit/test_http_parser_ng.rb @@ -388,6 +388,7 @@ class HttpParserNgTest < Test::Unit::TestCase "*" => { qs => "", pi => "" }, }.each do |uri,expect| assert_equal req, @parser.headers(req.clear, str % [ uri ]) + req = req.dup @parser.reset assert_equal uri, req["REQUEST_URI"], "REQUEST_URI mismatch" assert_equal expect[qs], req[qs], "#{qs} mismatch" @@ -412,6 +413,7 @@ class HttpParserNgTest < Test::Unit::TestCase "/1?a=b;c=d&e=f" => { qs => "a=b;c=d&e=f", pi => "/1" }, }.each do |uri,expect| assert_equal req, @parser.headers(req.clear, str % [ uri ]) + req = req.dup @parser.reset assert_equal uri, req["REQUEST_URI"], "REQUEST_URI mismatch" assert_equal "example.com", req["HTTP_HOST"], "Host: mismatch" @@ -440,6 +442,17 @@ class HttpParserNgTest < Test::Unit::TestCase end end + def test_backtrace_is_empty + begin + @parser.headers({}, "AAADFSFDSFD\r\n\r\n") + assert false, "should never get here line:#{__LINE__}" + rescue HttpParserError => e + assert_equal [], e.backtrace + return + end + assert false, "should never get here line:#{__LINE__}" + end + def test_ignore_version_header http = "GET / HTTP/1.1\r\nVersion: hello\r\n\r\n" req = {} @@ -460,4 +473,29 @@ class HttpParserNgTest < Test::Unit::TestCase assert_equal expect, req end + def test_pipelined_requests + expect = { + "HTTP_HOST" => "example.com", + "SERVER_NAME" => "example.com", + "REQUEST_PATH" => "/", + "rack.url_scheme" => "http", + "SERVER_PROTOCOL" => "HTTP/1.1", + "PATH_INFO" => "/", + "HTTP_VERSION" => "HTTP/1.1", + "REQUEST_URI" => "/", + "SERVER_PORT" => "80", + "REQUEST_METHOD" => "GET", + "QUERY_STRING" => "" + } + str = "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" + @parser.buf << (str * 2) + env1 = @parser.parse.dup + assert_equal expect, env1 + assert_equal str, @parser.buf + assert @parser.keepalive? + @parser.reset + env2 = @parser.parse.dup + assert_equal expect, env2 + assert_equal "", @parser.buf + end end diff --git a/test/unit/test_request.rb b/test/unit/test_request.rb index 1896300..67ac1b9 100644 --- a/test/unit/test_request.rb +++ b/test/unit/test_request.rb @@ -11,7 +11,11 @@ class RequestTest < Test::Unit::TestCase class MockRequest < StringIO alias_method :readpartial, :sysread + alias_method :kgio_read!, :sysread alias_method :read_nonblock, :sysread + def kgio_addr + '127.0.0.1' + end end def setup @@ -159,6 +163,14 @@ class RequestTest < Test::Unit::TestCase buf = (' ' * bs).freeze length = bs * count client = Tempfile.new('big_put') + def client.kgio_addr; '127.0.0.1'; end + def client.kgio_read(*args) + readpartial(*args) + rescue EOFError + end + def client.kgio_read!(*args) + readpartial(*args) + end client.syswrite( "PUT / HTTP/1.1\r\n" \ "Host: foo\r\n" \ diff --git a/test/unit/test_response.rb b/test/unit/test_response.rb index f9eda8e..e5245e8 100644 --- a/test/unit/test_response.rb +++ b/test/unit/test_response.rb @@ -11,10 +11,11 @@ require 'test/test_helper' include Unicorn class ResponseTest < Test::Unit::TestCase - + include Unicorn::HttpResponse + def test_response_headers out = StringIO.new - HttpResponse.write(out,[200, {"X-Whatever" => "stuff"}, ["cool"]]) + http_response_write(out,[200, {"X-Whatever" => "stuff"}, ["cool"]]) assert out.closed? assert out.length > 0, "output didn't have data" @@ -22,7 +23,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_string_status out = StringIO.new - HttpResponse.write(out,['200', {}, []]) + http_response_write(out,['200', {}, []]) assert out.closed? assert out.length > 0, "output didn't have data" assert_equal 1, out.string.split(/\r\n/).grep(/^Status: 200 OK/).size @@ -32,7 +33,7 @@ class ResponseTest < Test::Unit::TestCase old_ofs = $, $, = "\f\v" out = StringIO.new - HttpResponse.write(out,[200, {"X-k" => "cd","X-y" => "z"}, ["cool"]]) + http_response_write(out,[200, {"X-k" => "cd","X-y" => "z"}, ["cool"]]) assert out.closed? resp = out.string assert ! resp.include?("\f\v"), "output didn't use $, ($OFS)" @@ -42,7 +43,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_200 io = StringIO.new - HttpResponse.write(io, [200, {}, []]) + http_response_write(io, [200, {}, []]) assert io.closed? assert io.length > 0, "output didn't have data" end @@ -50,7 +51,7 @@ class ResponseTest < Test::Unit::TestCase def test_response_with_default_reason code = 400 io = StringIO.new - HttpResponse.write(io, [code, {}, []]) + http_response_write(io, [code, {}, []]) assert io.closed? lines = io.string.split(/\r\n/) assert_match(/.* Bad Request$/, lines.first, @@ -59,7 +60,7 @@ class ResponseTest < Test::Unit::TestCase def test_rack_multivalue_headers out = StringIO.new - HttpResponse.write(out,[200, {"X-Whatever" => "stuff\nbleh"}, []]) + http_response_write(out,[200, {"X-Whatever" => "stuff\nbleh"}, []]) assert out.closed? assert_match(/^X-Whatever: stuff\r\nX-Whatever: bleh\r\n/, out.string) end @@ -68,7 +69,7 @@ class ResponseTest < Test::Unit::TestCase # some broken clients still rely on it def test_status_header_added out = StringIO.new - HttpResponse.write(out,[200, {"X-Whatever" => "stuff"}, []]) + http_response_write(out,[200, {"X-Whatever" => "stuff"}, []]) assert out.closed? assert_equal 1, out.string.split(/\r\n/).grep(/^Status: 200 OK/i).size end @@ -79,7 +80,7 @@ class ResponseTest < Test::Unit::TestCase def test_status_header_ignores_app_hash out = StringIO.new header_hash = {"X-Whatever" => "stuff", 'StaTus' => "666" } - HttpResponse.write(out,[200, header_hash, []]) + http_response_write(out,[200, header_hash, []]) assert out.closed? assert_equal 1, out.string.split(/\r\n/).grep(/^Status: 200 OK/i).size assert_equal 1, out.string.split(/\r\n/).grep(/^Status:/i).size @@ -90,7 +91,7 @@ class ResponseTest < Test::Unit::TestCase body = StringIO.new(expect_body) body.rewind out = StringIO.new - HttpResponse.write(out,[200, {}, body]) + http_response_write(out,[200, {}, body]) assert out.closed? assert body.closed? assert_match(expect_body, out.string.split(/\r\n/).last) @@ -98,7 +99,7 @@ class ResponseTest < Test::Unit::TestCase def test_unknown_status_pass_through out = StringIO.new - HttpResponse.write(out,["666 I AM THE BEAST", {}, [] ]) + http_response_write(out,["666 I AM THE BEAST", {}, [] ]) assert out.closed? headers = out.string.split(/\r\n\r\n/).first.split(/\r\n/) assert %r{\AHTTP/\d\.\d 666 I AM THE BEAST\z}.match(headers[0]) diff --git a/test/unit/test_signals.rb b/test/unit/test_signals.rb index 7c78b44..71cf8f4 100644 --- a/test/unit/test_signals.rb +++ b/test/unit/test_signals.rb @@ -166,7 +166,7 @@ class SignalsTest < Test::Unit::TestCase expect = @bs * @count assert_equal(expect, got, "expect=#{expect} got=#{got}") assert_nothing_raised { sock.close } - end unless ENV['RBX_SKIP'] + end def test_request_read app = lambda { |env| diff --git a/test/unit/test_tee_input.rb b/test/unit/test_tee_input.rb index a127882..a10ca34 100644 --- a/test/unit/test_tee_input.rb +++ b/test/unit/test_tee_input.rb @@ -9,7 +9,7 @@ class TestTeeInput < Test::Unit::TestCase def setup @rs = $/ @env = {} - @rd, @wr = IO.pipe + @rd, @wr = Kgio::UNIXSocket.pair @rd.sync = @wr.sync = true @start_pid = $$ end @@ -27,8 +27,8 @@ class TestTeeInput < Test::Unit::TestCase end def test_gets_long - init_parser("hello", 5 + (4096 * 4 * 3) + "#$/foo#$/".size) - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + r = init_request("hello", 5 + (4096 * 4 * 3) + "#$/foo#$/".size) + ti = Unicorn::TeeInput.new(@rd, r) status = line = nil pid = fork { @rd.close @@ -48,8 +48,8 @@ class TestTeeInput < Test::Unit::TestCase end def test_gets_short - init_parser("hello", 5 + "#$/foo".size) - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + r = init_request("hello", 5 + "#$/foo".size) + ti = Unicorn::TeeInput.new(@rd, r) status = line = nil pid = fork { @rd.close @@ -67,8 +67,8 @@ class TestTeeInput < Test::Unit::TestCase end def test_small_body - init_parser('hello') - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + r = init_request('hello') + ti = Unicorn::TeeInput.new(@rd, r) assert_equal 0, @parser.content_length assert @parser.body_eof? assert_equal StringIO, ti.tmp.class @@ -80,8 +80,8 @@ class TestTeeInput < Test::Unit::TestCase end def test_read_with_buffer - init_parser('hello') - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + r = init_request('hello') + ti = Unicorn::TeeInput.new(@rd, r) buf = '' rv = ti.read(4, buf) assert_equal 'hell', rv @@ -95,8 +95,8 @@ class TestTeeInput < Test::Unit::TestCase end def test_big_body - init_parser('.' * Unicorn::Const::MAX_BODY << 'a') - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + r = init_request('.' * Unicorn::Const::MAX_BODY << 'a') + ti = Unicorn::TeeInput.new(@rd, r) assert_equal 0, @parser.content_length assert @parser.body_eof? assert_kind_of File, ti.tmp @@ -106,9 +106,9 @@ class TestTeeInput < Test::Unit::TestCase def test_read_in_full_if_content_length a, b = 300, 3 - init_parser('.' * b, 300) + r = init_request('.' * b, 300) assert_equal 300, @parser.content_length - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + ti = Unicorn::TeeInput.new(@rd, r) pid = fork { @wr.write('.' * 197) sleep 1 # still a *potential* race here that would make the test moot... @@ -121,8 +121,8 @@ class TestTeeInput < Test::Unit::TestCase end def test_big_body_multi - init_parser('.', Unicorn::Const::MAX_BODY + 1) - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + r = init_request('.', Unicorn::Const::MAX_BODY + 1) + ti = Unicorn::TeeInput.new(@rd, r) assert_equal Unicorn::Const::MAX_BODY, @parser.content_length assert ! @parser.body_eof? assert_kind_of File, ti.tmp @@ -163,7 +163,7 @@ class TestTeeInput < Test::Unit::TestCase @wr.write("0\r\n\r\n") } @wr.close - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + ti = Unicorn::TeeInput.new(@rd, @parser) assert_nil @parser.content_length assert_nil ti.len assert ! @parser.body_eof? @@ -201,7 +201,7 @@ class TestTeeInput < Test::Unit::TestCase end @wr.write("0\r\n\r\n") } - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + ti = Unicorn::TeeInput.new(@rd, @parser) assert_nil @parser.content_length assert_nil ti.len assert ! @parser.body_eof? @@ -230,7 +230,7 @@ class TestTeeInput < Test::Unit::TestCase @wr.write("Hello: World\r\n\r\n") } @wr.close - ti = Unicorn::TeeInput.new(@rd, @env, @parser, @buf) + ti = Unicorn::TeeInput.new(@rd, @parser) assert_nil @parser.content_length assert_nil ti.len assert ! @parser.body_eof? @@ -243,7 +243,7 @@ class TestTeeInput < Test::Unit::TestCase private - def init_parser(body, size = nil) + def init_request(body, size = nil) @parser = Unicorn::HttpParser.new body = body.to_s.freeze @buf = "POST / HTTP/1.1\r\n" \ @@ -252,6 +252,7 @@ private "\r\n#{body}" assert_equal @env, @parser.headers(@env, @buf) assert_equal body, @buf + @parser end end |