diff --git a/lib/vagrant/util/is_port_open.rb b/lib/vagrant/util/is_port_open.rb index a0a79b4f7..b51a01ecd 100644 --- a/lib/vagrant/util/is_port_open.rb +++ b/lib/vagrant/util/is_port_open.rb @@ -30,8 +30,7 @@ module Vagrant return true end rescue Timeout::Error, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, \ - Errno::ENETUNREACH, Errno::EACCES, Errno::ENOTCONN, \ - Errno::EADDRNOTAVAIL + Errno::ENETUNREACH, Errno::EACCES, Errno::ENOTCONN # Any of the above exceptions signal that the port is closed. return false end diff --git a/test/unit/vagrant/action/builtin/handle_forwarded_port_collisions_test.rb b/test/unit/vagrant/action/builtin/handle_forwarded_port_collisions_test.rb index 8594413d9..71b848102 100644 --- a/test/unit/vagrant/action/builtin/handle_forwarded_port_collisions_test.rb +++ b/test/unit/vagrant/action/builtin/handle_forwarded_port_collisions_test.rb @@ -69,7 +69,7 @@ describe Vagrant::Action::Builtin::HandleForwardedPortCollisions do end context "with forwarded port defined" do - let(:port_options){ {guest: 80, host: 8080} } + let(:port_options){ {guest: 80, host: 52811} } before do expect(vm_config).to receive(:networks).and_return([[:forwarded_port, port_options]]).twice end @@ -80,7 +80,7 @@ describe Vagrant::Action::Builtin::HandleForwardedPortCollisions do end context "with forwarded port already in use" do - let(:extra_in_use){ [8080] } + let(:extra_in_use){ [52811] } it "should raise a port collision error" do expect{ instance.call(env) }.to raise_error(Vagrant::Errors::ForwardPortCollision) @@ -105,7 +105,7 @@ describe Vagrant::Action::Builtin::HandleForwardedPortCollisions do context "with custom port_check method" do let(:check_result){ [] } - let(:port_options){ {guest: 80, host: 8080, host_ip: "127.0.1.1"} } + let(:port_options){ {guest: 80, host: 52811, host_ip: "127.0.1.1"} } context "that accepts two parameters" do let(:collision_port_check) do @@ -145,7 +145,7 @@ describe Vagrant::Action::Builtin::HandleForwardedPortCollisions do describe "#port_check" do let(:host_ip){ "127.0.0.1" } - let(:host_port){ 8080 } + let(:host_port){ 52811 } it "should check if the port is open" do expect(instance).to receive(:is_port_open?).with(host_ip, host_port).and_return true diff --git a/test/unit/vagrant/util/is_port_open_test.rb b/test/unit/vagrant/util/is_port_open_test.rb index ea7042575..ff6109639 100644 --- a/test/unit/vagrant/util/is_port_open_test.rb +++ b/test/unit/vagrant/util/is_port_open_test.rb @@ -49,5 +49,15 @@ describe Vagrant::Util::IsPortOpen do # best, really. expect(klass.is_port_open?("127.0.0.1", closed_port)).not_to be end + + it "should handle connection refused" do + expect(TCPSocket).to receive(:new).with("0.0.0.0", closed_port).and_raise Errno::ECONNREFUSED + expect(klass.is_port_open?("0.0.0.0", closed_port)).to be(false) + end + + it "should raise an error if cannot assign requested address" do + expect(TCPSocket).to receive(:new).with("0.0.0.0", open_port).and_raise Errno::EADDRNOTAVAIL + expect { klass.is_port_open?("0.0.0.0", open_port) }.to raise_error Errno::EADDRNOTAVAIL + end end