about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorluislavena <luislavena@19e92222-5c0b-0410-8929-a290d50e31e9>2008-03-31 08:19:11 +0000
committerluislavena <luislavena@19e92222-5c0b-0410-8929-a290d50e31e9>2008-03-31 08:19:11 +0000
commiteda1ea00904dcf4b4e7ed533b327a842713ac11a (patch)
treebf6e839153592c22c2c2f9b4745b823c0b3db1f0 /test
parent18e93c034db0c08bcc5b5f7a72a8fb6e909c009c (diff)
downloadunicorn-eda1ea00904dcf4b4e7ed533b327a842713ac11a.tar.gz
CI tools.
Use of #process_based_port as port number.
Exclude DirHandler(nil) with absolute paths on Windows.


git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/branches/stable_1-2@999 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'test')
-rw-r--r--test/test_helper.rb13
-rw-r--r--test/unit/test_conditional.rb2
-rw-r--r--test/unit/test_configurator.rb11
-rw-r--r--test/unit/test_handlers.rb39
-rw-r--r--test/unit/test_redirect_handler.rb5
-rw-r--r--test/unit/test_request_progress.rb9
-rw-r--r--test/unit/test_ws.rb7
7 files changed, 53 insertions, 33 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 42ead2c..7615fdd 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -64,3 +64,16 @@ 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
+
+# Platform check helper ;-)
+def windows?
+  result = RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/
+end \ No newline at end of file
diff --git a/test/unit/test_conditional.rb b/test/unit/test_conditional.rb
index 769dd91..64517db 100644
--- a/test/unit/test_conditional.rb
+++ b/test/unit/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/unit/test_configurator.rb b/test/unit/test_configurator.rb
index f55a8ae..dc9713a 100644
--- a/test/unit/test_configurator.rb
+++ b/test/unit/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 => process_based_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")
@@ -55,7 +56,7 @@ class ConfiguratorTest < Test::Unit::TestCase
         end
       end
     end
-
+    
     # pp @config.listeners.values.first.classifier.routes
 
     @config.listeners.each do |host,listener|
@@ -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/unit/test_handlers.rb b/test/unit/test_handlers.rb
index 27c0c08..66bf010 100644
--- a/test/unit/test_handlers.rb
+++ b/test/unit/test_handlers.rb
@@ -34,10 +34,11 @@ end
 class HandlersTest < Test::Unit::TestCase
 
   def setup
+    @port = process_based_port
     stats = Mongrel::StatisticsFilter.new(:sample_rate => 1)
 
-    @config = Mongrel::Configurator.new :host => '127.0.0.1', :port => 9998 do
-      listener do
+    @config = Mongrel::Configurator.new :host => '127.0.0.1' do
+      listener :port => process_based_port do
         uri "/", :handler => SimpleHandler.new
         uri "/", :handler => stats
         uri "/404", :handler => Mongrel::Error404Handler.new("Not found")
@@ -50,8 +51,10 @@ class HandlersTest < Test::Unit::TestCase
       end
     end
     
-    File.open("/tmp/testfile", 'w') do
-      # Do nothing
+    unless windows?
+      File.open('/tmp/testfile', 'w') do
+        # Do nothing
+      end
     end
     
     @config.run
@@ -59,7 +62,7 @@ class HandlersTest < Test::Unit::TestCase
 
   def teardown
     @config.stop(false, true)
-    File.delete "/tmp/testfile"
+    File.delete '/tmp/testfile' unless windows?
   end
   
   def test_registration_exception_is_not_lost
@@ -73,19 +76,20 @@ 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",
     ])
     check_status res, String
   end
   
   def test_nil_dirhandler
+    return if windows?
     # Camping uses this internally
     handler = Mongrel::DirHandler.new(nil, false)  
     assert handler.can_serve("/tmp/testfile")
@@ -102,7 +106,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(
@@ -120,14 +124,13 @@ class HandlersTest < Test::Unit::TestCase
 
   # TODO: find out why this fails on win32 but nowhere else
   #def test_posting_fails_dirhandler
-  #  req = Net::HTTP::Post.new("http://localhost:9998/files/rdoc/")
+  #  req = Net::HTTP::Post.new("http://localhost:#{@port}/files/rdoc/")
   #  req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
-  #  res = hit [["http://localhost:9998/files/rdoc/",req]]
+  #  res = hit [["http://localhost:#{@port}/files/rdoc/",req]]
   #  check_status res, Net::HTTPNotFound
   #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/unit/test_redirect_handler.rb b/test/unit/test_redirect_handler.rb
index 3207b46..e990427 100644
--- a/test/unit/test_redirect_handler.rb
+++ b/test/unit/test_redirect_handler.rb
@@ -9,11 +9,12 @@ require 'test/test_helper'
 class RedirectHandlerTest < 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
     @server.run
-    @client = Net::HTTP.new('127.0.0.1', 9998)
+    @client = Net::HTTP.new('127.0.0.1', @port)
   end
 
   def teardown
diff --git a/test/unit/test_request_progress.rb b/test/unit/test_request_progress.rb
index da9374e..a100426 100644
--- a/test/unit/test_request_progress.rb
+++ b/test/unit/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/unit/test_ws.rb b/test/unit/test_ws.rb
index 68a79a8..9de8a45 100644
--- a/test/unit/test_ws.rb
+++ b/test/unit/test_ws.rb
@@ -22,10 +22,11 @@ class WebServerTest < Test::Unit::TestCase
 
   def setup
     @valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n"
+    @port = process_based_port
     
     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