diff options
-rw-r--r-- | test/test_conditional.rb | 2 | ||||
-rw-r--r-- | test/test_configurator.rb | 9 | ||||
-rw-r--r-- | test/test_handlers.rb | 25 | ||||
-rw-r--r-- | test/test_redirect_handler.rb | 4 | ||||
-rw-r--r-- | test/test_request_progress.rb | 9 | ||||
-rw-r--r-- | test/test_ws.rb | 7 | ||||
-rw-r--r-- | test/testhelp.rb | 8 |
7 files changed, 38 insertions, 26 deletions
diff --git a/test/test_conditional.rb b/test/test_conditional.rb index cd3ce06..792a880 100644 --- a/test/test_conditional.rb +++ b/test/test_conditional.rb @@ -10,7 +10,7 @@ include Mongrel class ConditionalResponseTest < Test::Unit::TestCase def setup - @server = HttpServer.new('127.0.0.1', 3501) + @server = HttpServer.new('127.0.0.1', process_based_port) @server.register('/', Mongrel::DirHandler.new('.')) @server.run diff --git a/test/test_configurator.rb b/test/test_configurator.rb index dd99f00..fde2682 100644 --- a/test/test_configurator.rb +++ b/test/test_configurator.rb @@ -29,11 +29,12 @@ end class ConfiguratorTest < Test::Unit::TestCase def test_base_handler_config + port = process_based_port @config = nil redirect_test_io do @config = Mongrel::Configurator.new :host => "localhost" do - listener :port => 4501 do + listener :port => port 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") @@ -64,12 +65,12 @@ class ConfiguratorTest < Test::Unit::TestCase assert listener.classifier.uris.include?("/test"), "/test not registered" end - res = Net::HTTP.get(URI.parse('http://localhost:4501/test')) + res = Net::HTTP.get(URI.parse("http://localhost:#{port}/test")) 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:#{port}/")) assert res != nil, "Didn't get a response" assert $test_plugin_fired == 6, "Test filter plugin didn't run 6 times." @@ -80,7 +81,7 @@ class ConfiguratorTest < Test::Unit::TestCase end assert_raise Errno::EBADF, Errno::ECONNREFUSED do - res = Net::HTTP.get(URI.parse("http://localhost:4501/")) + res = Net::HTTP.get(URI.parse("http://localhost:#{port}/")) end end diff --git a/test/test_handlers.rb b/test/test_handlers.rb index 72abbbc..dc7667c 100644 --- a/test/test_handlers.rb +++ b/test/test_handlers.rb @@ -35,8 +35,9 @@ class HandlersTest < Test::Unit::TestCase def setup stats = Mongrel::StatisticsFilter.new(:sample_rate => 1) - - @config = Mongrel::Configurator.new :host => '127.0.0.1', :port => 9998 do + @port = process_based_port + + @config = Mongrel::Configurator.new :host => '127.0.0.1', :port => @port do listener do uri "/", :handler => SimpleHandler.new uri "/", :handler => stats @@ -57,14 +58,14 @@ class HandlersTest < Test::Unit::TestCase end def test_more_web_server - res = hit([ "http://localhost:9998/test", - "http://localhost:9998/dumb", - "http://localhost:9998/404", - "http://localhost:9998/files/rdoc/index.html", - "http://localhost:9998/files/rdoc/nothere.html", - "http://localhost:9998/files/rdoc/", - "http://localhost:9998/files_nodir/rdoc/", - "http://localhost:9998/status", + res = hit([ "http://localhost:#{@port}/test", + "http://localhost:#{@port}/dumb", + "http://localhost:#{@port}/404", + "http://localhost:#{@port}/files/rdoc/index.html", + "http://localhost:#{@port}/files/rdoc/nothere.html", + "http://localhost:#{@port}/files/rdoc/", + "http://localhost:#{@port}/files_nodir/rdoc/", + "http://localhost:#{@port}/status", ]) # XXX This can't possibly have good coverage. @@ -72,7 +73,7 @@ class HandlersTest < Test::Unit::TestCase end def test_deflate - Net::HTTP.start("localhost", 9998) do |h| + Net::HTTP.start("localhost", @port) do |h| # test that no accept-encoding returns a non-deflated response req = h.get("/dumb") assert( @@ -97,7 +98,7 @@ class HandlersTest < Test::Unit::TestCase #end def test_unregister - @config.listeners["127.0.0.1:9998"].unregister("/") + @config.listeners["127.0.0.1:#{@port}"].unregister("/") end end diff --git a/test/test_redirect_handler.rb b/test/test_redirect_handler.rb index 2e03d48..a4c5056 100644 --- a/test/test_redirect_handler.rb +++ b/test/test_redirect_handler.rb @@ -10,10 +10,10 @@ class RedirectHandlerTest < Test::Unit::TestCase def setup redirect_test_io do - @server = Mongrel::HttpServer.new('127.0.0.1', 9998) + @server = Mongrel::HttpServer.new('127.0.0.1', process_based_port) end @server.run - @client = Net::HTTP.new('127.0.0.1', 9998) + @client = Net::HTTP.new('127.0.0.1', process_based_port) end def teardown diff --git a/test/test_request_progress.rb b/test/test_request_progress.rb index ba21c27..4be9d16 100644 --- a/test/test_request_progress.rb +++ b/test/test_request_progress.rb @@ -38,8 +38,9 @@ end class RequestProgressTest < Test::Unit::TestCase def setup + @port = process_based_port redirect_test_io do - @server = Mongrel::HttpServer.new("127.0.0.1", 9998) + @server = Mongrel::HttpServer.new("127.0.0.1", @port) end @handler = UploadBeginHandler.new @server.register("/upload", @handler) @@ -51,7 +52,7 @@ class RequestProgressTest < Test::Unit::TestCase end def test_begin_end_progress - Net::HTTP.get("localhost", "/upload", 9998) + Net::HTTP.get("localhost", "/upload", @port) assert @handler.request_began assert @handler.request_progressed assert @handler.request_processed @@ -62,7 +63,7 @@ class RequestProgressTest < Test::Unit::TestCase handlers.each { |h| h.reset } # make the call - Net::HTTP.get("localhost", "/upload", 9998) + Net::HTTP.get("localhost", "/upload", @port) # assert that each one was fired handlers.each { |h| @@ -88,7 +89,7 @@ class RequestProgressTest < Test::Unit::TestCase # remove handlers to make sure they've all gone away @server.unregister("/upload") handlers.each { |h| h.reset } - Net::HTTP.get("localhost", "/upload", 9998) + Net::HTTP.get("localhost", "/upload", @port) handlers.each { |h| assert !h.request_began && !h.request_progressed && !h.request_processed } diff --git a/test/test_ws.rb b/test/test_ws.rb index f019122..237aa54 100644 --- a/test/test_ws.rb +++ b/test/test_ws.rb @@ -21,11 +21,12 @@ end class WebServerTest < Test::Unit::TestCase def setup + @port = process_based_port @valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n" redirect_test_io do # We set num_processors=1 so that we can test the reaping code - @server = HttpServer.new("127.0.0.1", 9998, num_processors=1) + @server = HttpServer.new("127.0.0.1", @port, num_processors=1) end @tester = TestHandler.new @@ -42,14 +43,14 @@ class WebServerTest < Test::Unit::TestCase end def test_simple_server - hit(['http://localhost:9998/test']) + hit(["http://localhost:#{@port}/test"]) assert @tester.ran_test, "Handler didn't really run" end def do_test(string, chunk, close_after=nil, shutdown_delay=0) # Do not use instance variables here, because it needs to be thread safe - socket = TCPSocket.new("127.0.0.1", 9998); + socket = TCPSocket.new("127.0.0.1", @port); request = StringIO.new(string) chunks_out = 0 diff --git a/test/testhelp.rb b/test/testhelp.rb index 42ead2c..4fe112d 100644 --- a/test/testhelp.rb +++ b/test/testhelp.rb @@ -64,3 +64,11 @@ def hit(uris) return results end + +# process_based_port provides a port number, usable for TCP and UDP +# connections based on $$ and with a 5000 as base. +# this is required if you perform several builds of mongrel in parallel +# (like continuous integration systems) +def process_based_port + 5000 + $$ % 1000 +end
\ No newline at end of file |