require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
require 'socket'

class NeverListenTest < Test::Unit::TestCase

  include LaunchableRoleTests

  def setup
    @object = Bane::Services::NeverListen.make(IRRELEVANT_PORT, Bane::Services::DEFAULT_HOST)
  end

  def test_never_connects
    service = Bane::Services::NeverListen.make(port, Bane::Services::DEFAULT_HOST)
    service.stdlog = StringIO.new
    service.start

    assert_times_out {
      TCPSocket.new('localhost', port)
    }
  ensure
    service.stop
  end

  def port
    4001
  end

end

require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
require 'socket'

class NeverListenTest < Test::Unit::TestCase

  include LaunchableRoleTests

  def setup
    @object = Bane::Services::NeverListen.make(IRRELEVANT_PORT, Bane::Services::DEFAULT_HOST)
  end

  def test_never_connects
    service = Bane::Services::NeverListen.make(port, Bane::Services::DEFAULT_HOST)
    service.stdlog = StringIO.new
    service.start

    assert_raise(Errno::ECONNREFUSED) {
      TCPSocket.new('localhost', port)
    }
  ensure
    service.stop
  end

  def port
    4001
  end

end

Test that a socket connection is refused.
Test that a socket connection is refused.

The previous version used the 'timeout' gem to ensure this never connected.  However, this test passed on Mac OS X 10.8.5 and immediately failed with an Errno::ECONNREFUSED on Ubuntu.  After removing this timeout, I also get an ECONNREFUSED error on the Mac after 8 seconds.

This first step should make the test pass on both platforms.  The next step may be to shrink the timeout on this test so it's not so slow on the Mac - possibly using another timeout technique.
