diff options
author | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-05-24 08:34:17 +0000 |
---|---|---|
committer | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-05-24 08:34:17 +0000 |
commit | 7b53a9afd2fa7ec7086ad8df1d92cc6c693b1bb1 (patch) | |
tree | f0760b8503bc09d6e0ec972dad0c0ea56fba9c11 /test | |
parent | 0a3041fea19904e0bfdf4854d081017b11516dc0 (diff) | |
download | unicorn-7b53a9afd2fa7ec7086ad8df1d92cc6c693b1bb1.tar.gz |
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@212 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'test')
-rw-r--r-- | test/test_configurator.rb | 57 | ||||
-rw-r--r-- | test/test_ws.rb | 28 | ||||
-rw-r--r-- | test/testhelp.rb | 13 |
3 files changed, 63 insertions, 35 deletions
diff --git a/test/test_configurator.rb b/test/test_configurator.rb index dbea1a7..fdc9921 100644 --- a/test/test_configurator.rb +++ b/test/test_configurator.rb @@ -19,6 +19,7 @@ require 'test/unit' require 'mongrel' require 'net/http' +require File.dirname(__FILE__) + "/testhelp.rb" $test_plugin_fired = 0 @@ -43,26 +44,30 @@ end class ConfiguratorTest < Test::Unit::TestCase def test_base_handler_config - config = Mongrel::Configurator.new :host => "localhost" do - listener :port => 4501 do - # 2 in front should run, but the sentinel shouldn't since dirhandler processes the request - uri "/", :handler => plugin("/handlers/testplugin") - uri "/", :handler => plugin("/handlers/testplugin") - uri "/", :handler => Mongrel::DirHandler.new(".") - uri "/", :handler => plugin("/handlers/testplugin") - - uri "/test", :handler => plugin("/handlers/testplugin") - uri "/test", :handler => plugin("/handlers/testplugin") - uri "/test", :handler => Mongrel::DirHandler.new(".") - uri "/test", :handler => plugin("/handlers/testplugin") - - debug "/" - setup_signals - - run_config(File.dirname(__FILE__) + "/../test/mongrel.conf") - load_mime_map(File.dirname(__FILE__) + "/../examples/mime.yaml") - - run + config = nil + + redirect_test_io do + config = Mongrel::Configurator.new :host => "localhost" do + listener :port => 4501 do + # 2 in front should run, but the sentinel shouldn't since dirhandler processes the request + uri "/", :handler => plugin("/handlers/testplugin") + uri "/", :handler => plugin("/handlers/testplugin") + uri "/", :handler => Mongrel::DirHandler.new(".") + uri "/", :handler => plugin("/handlers/testplugin") + + uri "/test", :handler => plugin("/handlers/testplugin") + uri "/test", :handler => plugin("/handlers/testplugin") + uri "/test", :handler => Mongrel::DirHandler.new(".") + uri "/test", :handler => plugin("/handlers/testplugin") + + debug "/" + setup_signals + + run_config(File.dirname(__FILE__) + "/../test/mongrel.conf") + load_mime_map(File.dirname(__FILE__) + "/../examples/mime.yaml") + + run + end end end @@ -77,12 +82,16 @@ class ConfiguratorTest < Test::Unit::TestCase assert res != nil, "Didn't get a response" assert $test_plugin_fired == 3, "Test filter plugin didn't run 3 times." + redirect_test_io do + res = Net::HTTP.get(URI.parse('http://localhost:4501/')) - res = Net::HTTP.get(URI.parse('http://localhost:4501/')) - assert res != nil, "Didn't get a response" - assert $test_plugin_fired == 6, "Test filter plugin didn't run 6 times." + assert res != nil, "Didn't get a response" + assert $test_plugin_fired == 6, "Test filter plugin didn't run 6 times." + end - config.stop + redirect_test_io do + config.stop + end assert_raise Errno::EBADF, Errno::ECONNREFUSED do res = Net::HTTP.get(URI.parse("http://localhost:4501/")) diff --git a/test/test_ws.rb b/test/test_ws.rb index daf78d6..4945e4e 100644 --- a/test/test_ws.rb +++ b/test/test_ws.rb @@ -88,24 +88,30 @@ class WebServerTest < Test::Unit::TestCase end def test_bad_client - do_test("GET /test HTTP/BAD", 3) + redirect_test_io do + do_test("GET /test HTTP/BAD", 3) + end end def test_header_is_too_long - long = "GET /test HTTP/1.1\r\n" + ("X-Big: stuff\r\n" * 15000) + "\r\n" - assert_raises Errno::ECONNRESET, Errno::EPIPE do - do_test(long, long.length/2) + redirect_test_io do + long = "GET /test HTTP/1.1\r\n" + ("X-Big: stuff\r\n" * 15000) + "\r\n" + assert_raises Errno::ECONNRESET, Errno::EPIPE do + do_test(long, long.length/2) + end end end def test_num_processors_overload - assert_raises Errno::ECONNRESET, Errno::EPIPE do - tests = [ - Thread.new { do_test(@request, 1) }, - Thread.new { do_test(@request, 10) }, - ] - - tests.each {|t| t.join} + redirect_test_io do + assert_raises Errno::ECONNRESET, Errno::EPIPE do + tests = [ + Thread.new { do_test(@request, 1) }, + Thread.new { do_test(@request, 10) }, + ] + + tests.each {|t| t.join} + end end end diff --git a/test/testhelp.rb b/test/testhelp.rb new file mode 100644 index 0000000..7c0989b --- /dev/null +++ b/test/testhelp.rb @@ -0,0 +1,13 @@ +def redirect_test_io + orig_err = STDERR.dup + orig_out = STDOUT.dup + STDERR.reopen("test_stderr.log") + STDOUT.reopen("test_stdout.log") + + begin + yield + ensure + STDERR.reopen(orig_err) + STDOUT.reopen(orig_out) + end +end |