From fab6173a056990b3c3ed5756ac0624654bb6308f Mon Sep 17 00:00:00 2001 From: evanweaver Date: Sat, 20 Oct 2007 23:15:19 +0000 Subject: use synchronous stop everywhere; clean up test helpers git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@705 19e92222-5c0b-0410-8929-a290d50e31e9 --- Rakefile | 2 +- test/test_cgi_wrapper.rb | 6 ++---- test/test_command.rb | 5 +---- test/test_conditional.rb | 24 ++++++------------------ test/test_configurator.rb | 13 +++++-------- test/test_debug.rb | 5 +---- test/test_handlers.rb | 8 ++------ test/test_http11.rb | 6 +----- test/test_redirect_handler.rb | 8 ++------ test/test_request_progress.rb | 2 +- test/test_response.rb | 4 +--- test/test_stats.rb | 4 +--- test/test_uriclassifier.rb | 5 +---- test/test_ws.rb | 6 +----- test/testhelp.rb | 14 ++++++++++++++ 15 files changed, 40 insertions(+), 72 deletions(-) diff --git a/Rakefile b/Rakefile index a343d00..8c2fcab 100644 --- a/Rakefile +++ b/Rakefile @@ -63,7 +63,7 @@ end task :test_java do e.test_pattern.each do |f| - sh "/opt/local/jruby/bin/jruby -w -Ilib:ext:bin:test -e 'require \"#{f}\"; require \"test/unit\"'" rescue nil + sh "/opt/local/jruby/bin/jruby -w -Ilib:ext:bin:test -e 'require \"#{f}\"'" rescue nil end end diff --git a/test/test_cgi_wrapper.rb b/test/test_cgi_wrapper.rb index 0db0655..449f6d0 100644 --- a/test/test_cgi_wrapper.rb +++ b/test/test_cgi_wrapper.rb @@ -1,7 +1,5 @@ -require 'test/unit' -require 'rubygems' -require 'mongrel' -require 'cgi/session' + +require 'test/testhelp' class MockHttpRequest attr_reader :body diff --git a/test/test_command.rb b/test/test_command.rb index 4db9c1f..3cb9643 100644 --- a/test/test_command.rb +++ b/test/test_command.rb @@ -4,10 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'mongrel' -require File.dirname(__FILE__) + '/testhelp.rb' - +require 'test/testhelp' class TestCommand < GemPlugin::Plugin "/commands" include Mongrel::Command::Base diff --git a/test/test_conditional.rb b/test/test_conditional.rb index f2f01df..cd3ce06 100644 --- a/test/test_conditional.rb +++ b/test/test_conditional.rb @@ -4,19 +4,17 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'net/http' -require 'mongrel' +require 'test/testhelp' include Mongrel class ConditionalResponseTest < Test::Unit::TestCase def setup - @h = HttpServer.new('127.0.0.1', 3501) - @h.register('/', Mongrel::DirHandler.new('.')) - @h.run + @server = HttpServer.new('127.0.0.1', 3501) + @server.register('/', Mongrel::DirHandler.new('.')) + @server.run - @http = Net::HTTP.new(@h.host, @h.port) + @http = Net::HTTP.new(@server.host, @server.port) # get the ETag and Last-Modified headers @path = '/README' @@ -27,17 +25,7 @@ class ConditionalResponseTest < Test::Unit::TestCase end def teardown - orig_stderr = STDERR.dup - - # temporarily disable the puts method in STDERR to silence warnings from stop - class << STDERR - define_method(:puts) {} - end - - @h.stop - ensure - # restore STDERR - STDERR.reopen(orig_stderr) + @server.stop(true) end # status should be 304 Not Modified when If-None-Match is the matching ETag diff --git a/test/test_configurator.rb b/test/test_configurator.rb index d8e9a11..50e5037 100644 --- a/test/test_configurator.rb +++ b/test/test_configurator.rb @@ -4,10 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'mongrel' -require 'net/http' -require File.dirname(__FILE__) + "/testhelp.rb" +require 'test/testhelp' $test_plugin_fired = 0 @@ -32,10 +29,10 @@ end class ConfiguratorTest < Test::Unit::TestCase def test_base_handler_config - config = nil + @config = nil redirect_test_io do - config = Mongrel::Configurator.new :host => "localhost" 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") @@ -60,7 +57,7 @@ class ConfiguratorTest < Test::Unit::TestCase end - config.listeners.each do |host,listener| + @config.listeners.each do |host,listener| assert listener.classifier.uris.length == 3, "Wrong number of registered URIs" assert listener.classifier.uris.include?("/"), "/ not registered" assert listener.classifier.uris.include?("/test"), "/test not registered" @@ -78,7 +75,7 @@ class ConfiguratorTest < Test::Unit::TestCase end redirect_test_io do - config.stop(false, true) + @config.stop(false, true) end assert_raise Errno::EBADF, Errno::ECONNREFUSED do diff --git a/test/test_debug.rb b/test/test_debug.rb index 085fee0..72c352a 100644 --- a/test/test_debug.rb +++ b/test/test_debug.rb @@ -4,10 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'mongrel/rails' -require 'mongrel/debug' -require 'fileutils' +require 'test/testhelp' class MongrelDbgTest < Test::Unit::TestCase diff --git a/test/test_handlers.rb b/test/test_handlers.rb index fd8437d..ef858c8 100644 --- a/test/test_handlers.rb +++ b/test/test_handlers.rb @@ -4,11 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'net/http' -require 'mongrel' -require 'timeout' -require File.dirname(__FILE__) + "/testhelp.rb" +require 'test/testhelp' class SimpleHandler < Mongrel::HttpHandler def process(request, response) @@ -56,7 +52,7 @@ class HandlersTest < Test::Unit::TestCase end def teardown - @config.stop + @config.stop(false, true) end def test_more_web_server diff --git a/test/test_http11.rb b/test/test_http11.rb index 11d0bc3..da311af 100644 --- a/test/test_http11.rb +++ b/test/test_http11.rb @@ -4,11 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'http11' -require 'mongrel' -require 'benchmark' -require 'digest/sha1' +require 'test/testhelp' include Mongrel diff --git a/test/test_redirect_handler.rb b/test/test_redirect_handler.rb index dc81647..f970203 100644 --- a/test/test_redirect_handler.rb +++ b/test/test_redirect_handler.rb @@ -4,11 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'mongrel' -require 'net/http' -require 'uri' -require 'timeout' +require 'test/testhelp' class RedirectHandlerTest < Test::Unit::TestCase @@ -19,7 +15,7 @@ class RedirectHandlerTest < Test::Unit::TestCase end def teardown - @server.stop + @server.stop(true) end def test_simple_redirect diff --git a/test/test_request_progress.rb b/test/test_request_progress.rb index 63a2742..a1bf1ec 100644 --- a/test/test_request_progress.rb +++ b/test/test_request_progress.rb @@ -49,7 +49,7 @@ class RequestProgressTest < Test::Unit::TestCase end def teardown - @server.stop + @server.stop(true) end def test_begin_end_progress diff --git a/test/test_response.rb b/test/test_response.rb index 90953b1..123ed98 100644 --- a/test/test_response.rb +++ b/test/test_response.rb @@ -4,9 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'mongrel' -require 'benchmark' +require 'test/testhelp' include Mongrel diff --git a/test/test_stats.rb b/test/test_stats.rb index e37f2e2..404870a 100644 --- a/test/test_stats.rb +++ b/test/test_stats.rb @@ -4,9 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'mongrel/stats' -require 'stringio' +require 'test/testhelp' class StatsTest < Test::Unit::TestCase diff --git a/test/test_uriclassifier.rb b/test/test_uriclassifier.rb index 1fe2ef7..0075990 100644 --- a/test/test_uriclassifier.rb +++ b/test/test_uriclassifier.rb @@ -4,10 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'net/http' -require 'mongrel' -require 'benchmark' +require 'test/testhelp' include Mongrel diff --git a/test/test_ws.rb b/test/test_ws.rb index feb3a27..e4a3448 100644 --- a/test/test_ws.rb +++ b/test/test_ws.rb @@ -4,11 +4,7 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. -require 'test/unit' -require 'net/http' -require 'mongrel' -require 'timeout' -require File.dirname(__FILE__) + "/testhelp.rb" +require 'test/testhelp' include Mongrel diff --git a/test/testhelp.rb b/test/testhelp.rb index 9bf719f..cc5ba4c 100644 --- a/test/testhelp.rb +++ b/test/testhelp.rb @@ -4,6 +4,20 @@ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html # for more information. +require 'rubygems' +require 'test/unit' +require 'net/http' +require 'timeout' +require 'cgi/session' +require 'fileutils' +require 'benchmark' +require 'digest/sha1' +require 'uri' +require 'stringio' + +require 'mongrel' +require 'mongrel/stats' + if ENV['DEBUG'] require 'ruby-debug' Debugger.start -- cgit v1.2.3-24-ge0c7