Sha256: f2041033f0e755a8ead38096914f0c86020bca545eb75163e1f551b1de5f4147

Contents?: true

Size: 1.17 KB

Versions: 38

Compression:

Stored size: 1.17 KB

Contents

require File.expand_path("../../../base", __FILE__)

require "socket"

require "vagrant/util/is_port_open"

describe Vagrant::Util::IsPortOpen do
  let(:klass) do
    Class.new do
      extend Vagrant::Util::IsPortOpen
    end
  end

  let(:open_port)   { 52811 }
  let(:closed_port) { 52811 }

  it "should report open ports" do
    # Start a thread which listens on a port
    thr = Thread.new do
      server = TCPServer.new(open_port)
      Thread.current[:running] = true

      # Wait until we're told to die
      Thread.current[:die]     = false
      while !Thread.current[:die]
        Thread.pass
      end

      # Die!
      server.close
    end

    # Wait until the server is running
    while !thr[:running]
      Thread.pass
    end

    # Verify that we report the port is open
    klass.is_port_open?("localhost", open_port).should be

    # Kill the thread
    thr[:die] = true
    thr.join
  end

  it "should report closed ports" do
    # This CAN fail, since port 52811 might actually be in use, but I'm
    # not sure what to do except choose some random port and hope for the
    # best, really.
    klass.is_port_open?("localhost", closed_port).should_not be
  end
end

Version data entries

38 entries across 38 versions & 11 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/test/unit/vagrant/util/is_port_open_test.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/test/unit/vagrant/util/is_port_open_test.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/test/unit/vagrant/util/is_port_open_test.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/test/unit/vagrant/util/is_port_open_test.rb
bmhatfield-vagrant-1.0.10 test/unit/vagrant/util/is_port_open_test.rb
bmhatfield-vagrant-1.0.9 test/unit/vagrant/util/is_port_open_test.rb
tnargav-1.3.6 test/unit/vagrant/util/is_port_open_test.rb
tnargav-1.3.3 test/unit/vagrant/util/is_port_open_test.rb
bmhatfield-vagrant-1.0.8 test/unit/vagrant/util/is_port_open_test.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/test/unit/vagrant/util/is_port_open_test.rb
tnargav-1.2.3 test/unit/vagrant/util/is_port_open_test.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/test/unit/vagrant/util/is_port_open_test.rb
bmhatfield-vagrant-1.0.7 test/unit/vagrant/util/is_port_open_test.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/test/unit/vagrant/util/is_port_open_test.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/test/unit/vagrant/util/is_port_open_test.rb
tnargav-1.2.2 test/unit/vagrant/util/is_port_open_test.rb
vagrantup-1.1.3 test/unit/vagrant/util/is_port_open_test.rb
vagrantup-1.1.2 test/unit/vagrant/util/is_port_open_test.rb
vagrantup-1.1.1 test/unit/vagrant/util/is_port_open_test.rb
vagrantup-1.1.0 test/unit/vagrant/util/is_port_open_test.rb