Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove fixed port numbers used in tests, make tests more friendly to

CI tools.
Use of #process_based_port as port number.


git-svn-id: svn://rubyforge.org/var/svn/mongrel/trunk@998 19e92222-5c0b-0410-8929-a290d50e31e9
  • Loading branch information...
commit 0168a7ac280770cd9df867f86ec0de1437455778 1 parent d38c66f
luislavena authored
2  test/test_conditional.rb
View
@@ -10,7 +10,7 @@
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
9 test/test_configurator.rb
View
@@ -29,11 +29,12 @@ def process(request, response)
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 @@ def test_base_handler_config
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 @@ def test_base_handler_config
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
25 test/test_handlers.rb
View
@@ -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 @@ def teardown
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 @@ def test_more_web_server
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 @@ def test_deflate
#end
def test_unregister
- @config.listeners["127.0.0.1:9998"].unregister("/")
+ @config.listeners["127.0.0.1:#{@port}"].unregister("/")
end
end
4 test/test_redirect_handler.rb
View
@@ -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
9 test/test_request_progress.rb
View
@@ -38,8 +38,9 @@ def process(request, response)
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 @@ def teardown
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 @@ def call_and_assert_handlers_in_turn(handlers)
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 @@ def test_more_than_one_begin_end_progress
# 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
}
7 test/test_ws.rb
View
@@ -21,11 +21,12 @@ def process(request, response)
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 @@ def teardown
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
8 test/testhelp.rb
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.