Changeset 999

Show
Ignore:
Timestamp:
03/31/08 03:19:11 (5 months ago)
Author:
luislavena
Message:

Remove fixed port numbers used in tests, make tests more friendly to
CI tools.
Use of #process_based_port as port number.
Exclude DirHandler?(nil) with absolute paths on Windows.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/stable_1-2

    • Property bzr:revision-id:v3-trunk0 set to
      814 luislavena@gmail.com-20080331074345-8r7ghwi05bwwqz7f
    • Property bzr:file-ids set
    • Property bzr:revision-info set to
      timestamp: 2008-03-31 04:43:45.765000105 -0300
      committer: Luis Lavena <luislavena@gmail.com>
      properties:
      branch-nick: stable_1-2
  • branches/stable_1-2/test/test_helper.rb

    r973 r999  
    6565  return results 
    6666end 
     67 
     68# process_based_port provides a port number, usable for TCP and UDP   
     69# connections based on $$ and with a 5000 as base.  
     70# this is required if you perform several builds of mongrel in parallel  
     71# (like continuous integration systems)  
     72def process_based_port  
     73  5000 + $$ % 1000  
     74end 
     75 
     76# Platform check helper ;-) 
     77def windows? 
     78  result = RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/ 
     79end 
  • branches/stable_1-2/test/unit/test_conditional.rb

    r973 r999  
    1111class ConditionalResponseTest < Test::Unit::TestCase 
    1212  def setup 
    13     @server = HttpServer.new('127.0.0.1', 3501
     13    @server = HttpServer.new('127.0.0.1', process_based_port
    1414    @server.register('/', Mongrel::DirHandler.new('.')) 
    1515    @server.run 
  • branches/stable_1-2/test/unit/test_configurator.rb

    r973 r999  
    3030 
    3131  def test_base_handler_config 
     32    @port = process_based_port 
    3233    @config = nil 
    3334 
    3435    redirect_test_io do 
    3536      @config = Mongrel::Configurator.new :host => "localhost" do 
    36         listener :port => 4501 do 
     37        listener :port => process_based_port do 
    3738          # 2 in front should run, but the sentinel shouldn't since dirhandler processes the request 
    3839          uri "/", :handler => plugin("/handlers/testplugin") 
     
    5657      end 
    5758    end 
    58  
     59     
    5960    # pp @config.listeners.values.first.classifier.routes 
    6061 
     
    6566    end 
    6667 
    67     res = Net::HTTP.get(URI.parse('http://localhost:4501/test')) 
     68    res = Net::HTTP.get(URI.parse("http://localhost:#{@port}/test")) 
    6869    assert res != nil, "Didn't get a response" 
    6970    assert $test_plugin_fired == 3, "Test filter plugin didn't run 3 times." 
    7071 
    7172    redirect_test_io do 
    72       res = Net::HTTP.get(URI.parse('http://localhost:4501/')) 
     73      res = Net::HTTP.get(URI.parse("http://localhost:#{@port}/")) 
    7374 
    7475      assert res != nil, "Didn't get a response" 
     
    8182 
    8283    assert_raise Errno::EBADF, Errno::ECONNREFUSED do 
    83       res = Net::HTTP.get(URI.parse("http://localhost:4501/")) 
     84      res = Net::HTTP.get(URI.parse("http://localhost:#{@port}/")) 
    8485    end 
    8586  end 
  • branches/stable_1-2/test/unit/test_handlers.rb

    r995 r999  
    3535 
    3636  def setup 
     37    @port = process_based_port 
    3738    stats = Mongrel::StatisticsFilter.new(:sample_rate => 1) 
    3839 
    39     @config = Mongrel::Configurator.new :host => '127.0.0.1', :port => 9998 do 
    40       listener do 
     40    @config = Mongrel::Configurator.new :host => '127.0.0.1' do 
     41      listener :port => process_based_port do 
    4142        uri "/", :handler => SimpleHandler.new 
    4243        uri "/", :handler => stats 
     
    5152    end 
    5253     
    53     File.open("/tmp/testfile", 'w') do 
    54       # Do nothing 
     54    unless windows? 
     55      File.open('/tmp/testfile', 'w') do 
     56        # Do nothing 
     57      end 
    5558    end 
    5659     
     
    6063  def teardown 
    6164    @config.stop(false, true) 
    62     File.delete "/tmp/testfile" 
     65    File.delete '/tmp/testfile' unless windows? 
    6366  end 
    6467   
     
    7477 
    7578  def test_more_web_server 
    76     res = hit([ "http://localhost:9998/test", 
    77           "http://localhost:9998/dumb", 
    78           "http://localhost:9998/404", 
    79           "http://localhost:9998/files/rdoc/index.html", 
    80           "http://localhost:9998/files/rdoc/nothere.html", 
    81           "http://localhost:9998/files/rdoc/", 
    82           "http://localhost:9998/files_nodir/rdoc/", 
    83           "http://localhost:9998/status", 
     79    res = hit([ "http://localhost:#{@port}/test", 
     80          "http://localhost:#{@port}/dumb", 
     81          "http://localhost:#{@port}/404", 
     82          "http://localhost:#{@port}/files/rdoc/index.html", 
     83          "http://localhost:#{@port}/files/rdoc/nothere.html", 
     84          "http://localhost:#{@port}/files/rdoc/", 
     85          "http://localhost:#{@port}/files_nodir/rdoc/", 
     86          "http://localhost:#{@port}/status", 
    8487    ]) 
    8588    check_status res, String 
     
    8790   
    8891  def test_nil_dirhandler 
     92    return if windows? 
    8993    # Camping uses this internally 
    9094    handler = Mongrel::DirHandler.new(nil, false)   
     
    103107 
    104108  def test_deflate 
    105     Net::HTTP.start("localhost", 9998) do |h| 
     109    Net::HTTP.start("localhost", @port) do |h| 
    106110      # Test that no accept-encoding returns a non-deflated response 
    107111      req = h.get("/dumb") 
     
    121125  # TODO: find out why this fails on win32 but nowhere else 
    122126  #def test_posting_fails_dirhandler 
    123   #  req = Net::HTTP::Post.new("http://localhost:9998/files/rdoc/") 
     127  #  req = Net::HTTP::Post.new("http://localhost:#{@port}/files/rdoc/") 
    124128  #  req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';') 
    125   #  res = hit [["http://localhost:9998/files/rdoc/",req]] 
     129  #  res = hit [["http://localhost:#{@port}/files/rdoc/",req]] 
    126130  #  check_status res, Net::HTTPNotFound 
    127131  #end 
    128132 
    129133  def test_unregister 
    130     @config.listeners["127.0.0.1:9998"].unregister("/") 
     134    @config.listeners["127.0.0.1:#{@port}"].unregister("/") 
    131135  end 
    132136end 
    133  
  • branches/stable_1-2/test/unit/test_redirect_handler.rb

    r973 r999  
    1010 
    1111  def setup 
     12    @port = process_based_port 
    1213    redirect_test_io do 
    13       @server = Mongrel::HttpServer.new('127.0.0.1', 9998
     14      @server = Mongrel::HttpServer.new('127.0.0.1', @port
    1415    end 
    1516    @server.run 
    16     @client = Net::HTTP.new('127.0.0.1', 9998
     17    @client = Net::HTTP.new('127.0.0.1', @port
    1718  end 
    1819 
  • branches/stable_1-2/test/unit/test_request_progress.rb

    r973 r999  
    3939class RequestProgressTest < Test::Unit::TestCase 
    4040  def setup 
     41    @port = process_based_port 
    4142    redirect_test_io do 
    42       @server = Mongrel::HttpServer.new("127.0.0.1", 9998
     43      @server = Mongrel::HttpServer.new("127.0.0.1", @port
    4344    end 
    4445    @handler = UploadBeginHandler.new 
     
    5253 
    5354  def test_begin_end_progress 
    54     Net::HTTP.get("localhost", "/upload", 9998
     55    Net::HTTP.get("localhost", "/upload", @port
    5556    assert @handler.request_began 
    5657    assert @handler.request_progressed 
     
    6364 
    6465    # make the call 
    65     Net::HTTP.get("localhost", "/upload", 9998
     66    Net::HTTP.get("localhost", "/upload", @port
    6667 
    6768    # assert that each one was fired 
     
    8990    @server.unregister("/upload") 
    9091    handlers.each { |h| h.reset } 
    91     Net::HTTP.get("localhost", "/upload", 9998
     92    Net::HTTP.get("localhost", "/upload", @port
    9293    handlers.each { |h| 
    9394      assert !h.request_began && !h.request_progressed && !h.request_processed 
  • branches/stable_1-2/test/unit/test_ws.rb

    r986 r999  
    2323  def setup 
    2424    @valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n" 
     25    @port = process_based_port 
    2526     
    2627    redirect_test_io do 
    2728      # We set num_processors=1 so that we can test the reaping code 
    28       @server = HttpServer.new("127.0.0.1", 9998, num_processors=1) 
     29      @server = HttpServer.new("127.0.0.1", @port, num_processors=1) 
    2930    end 
    3031     
     
    4344 
    4445  def test_simple_server 
    45     hit(['http://localhost:9998/test']) 
     46    hit(["http://localhost:#{@port}/test"]) 
    4647    assert @tester.ran_test, "Handler didn't really run" 
    4748  end 
     
    5051  def do_test(string, chunk, close_after=nil, shutdown_delay=0) 
    5152    # Do not use instance variables here, because it needs to be thread safe 
    52     socket = TCPSocket.new("127.0.0.1", 9998); 
     53    socket = TCPSocket.new("127.0.0.1", @port); 
    5354    request = StringIO.new(string) 
    5455    chunks_out = 0