diff options
Diffstat (limited to 'test/unit/test_server.rb')
-rw-r--r-- | test/unit/test_server.rb | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/test/unit/test_server.rb b/test/unit/test_server.rb index d19064c..742b240 100644 --- a/test/unit/test_server.rb +++ b/test/unit/test_server.rb @@ -25,8 +25,8 @@ class WebServerTest < Test::Unit::TestCase @tester = TestHandler.new redirect_test_io do @server = HttpServer.new(@tester, :listeners => [ "127.0.0.1:#{@port}" ] ) + @server.start end - @server.start end def teardown @@ -35,6 +35,60 @@ class WebServerTest < Test::Unit::TestCase end end + def test_preload_app_config + teardown + tmp = Tempfile.new('test_preload_app_config') + ObjectSpace.undefine_finalizer(tmp) + app = lambda { || + tmp.sysseek(0) + tmp.truncate(0) + tmp.syswrite($$) + lambda { |env| [ 200, { 'Content-Type' => 'text/plain' }, [ "#$$\n" ] ] } + } + redirect_test_io do + @server = HttpServer.new(app, :listeners => [ "127.0.0.1:#@port"] ) + @server.start + end + results = hit(["http://localhost:#@port/"]) + worker_pid = results[0].to_i + tmp.sysseek(0) + loader_pid = tmp.sysread(4096).to_i + assert_equal worker_pid, loader_pid + teardown + + redirect_test_io do + @server = HttpServer.new(app, :listeners => [ "127.0.0.1:#@port"], + :preload_app => true) + @server.start + end + results = hit(["http://localhost:#@port/"]) + worker_pid = results[0].to_i + tmp.sysseek(0) + loader_pid = tmp.sysread(4096).to_i + assert_equal $$, loader_pid + assert worker_pid != loader_pid + ensure + tmp.close! + end + + def test_broken_app + teardown + app = lambda { |env| raise RuntimeError, "hello" } + # [200, {}, []] } + redirect_test_io do + @server = HttpServer.new(app, :listeners => [ "127.0.0.1:#@port"] ) + @server.start + end + sock = nil + assert_nothing_raised do + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\n\r\n") + end + + assert_match %r{\AHTTP/1.[01] 500\b}, sock.sysread(4096) + assert_nothing_raised { sock.close } + end + def test_simple_server results = hit(["http://localhost:#{@port}/test"]) assert_equal 'hello!\n', results[0], "Handler didn't really run" @@ -77,6 +131,16 @@ class WebServerTest < Test::Unit::TestCase end end + def test_bad_client_400 + sock = nil + assert_nothing_raised do + sock = TCPSocket.new('127.0.0.1', @port) + sock.syswrite("GET / HTTP/1.0\r\nHost: foo\rbar\r\n\r\n") + end + assert_match %r{\AHTTP/1.[01] 400\b}, sock.sysread(4096) + assert_nothing_raised { sock.close } + end + def test_header_is_too_long redirect_test_io do long = "GET /test HTTP/1.1\r\n" + ("X-Big: stuff\r\n" * 15000) + "\r\n" |