diff --git a/CHANGELOG.md b/CHANGELOG.md index 09a9220f4..42574ff8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Arbitrary options to puppet binary can be set with `config.puppet.options`. [GH-242] - BSD hosts use proper GNU sed syntax for clearing NFS shares. [GH-243] - Enumerate VMs in a multi-VM environment in order they were defined. [GH-244] + - Check for VM boot changed to use `timeout` library, which works better with Windows. ## 0.6.8 (November 30, 2010) diff --git a/lib/vagrant/ssh.rb b/lib/vagrant/ssh.rb index 987d20e3d..38f1424de 100644 --- a/lib/vagrant/ssh.rb +++ b/lib/vagrant/ssh.rb @@ -1,3 +1,4 @@ +require 'timeout' require 'net/ssh' require 'net/scp' require 'mario' @@ -92,21 +93,16 @@ module Vagrant # # @return [Boolean] def up? - check_thread = Thread.new do - begin - Thread.current[:result] = false - execute(:timeout => env.config.ssh.timeout) do |ssh| - Thread.current[:result] = true - end - rescue Errno::ECONNREFUSED, Net::SSH::Disconnect, Errors::SSHConnectionRefused - # False, its defaulted above - end + Timeout.timeout(env.config.ssh.timeout) do + execute(:timeout => env.config.ssh.timeout) { |ssh| } end - check_thread.join(env.config.ssh.timeout) - return check_thread[:result] + true rescue Net::SSH::AuthenticationFailed raise Errors::SSHAuthenticationFailed.new + rescue Timeout::Error, Errno::ECONNREFUSED, Net::SSH::Disconnect, + Errors::SSHConnectionRefused, Net::SSH::AuthenticationFailed + return false end # Checks the file permissions for the private key, resetting them diff --git a/test/vagrant/ssh_test.rb b/test/vagrant/ssh_test.rb index 6aa970dd0..93542c5f9 100644 --- a/test/vagrant/ssh_test.rb +++ b/test/vagrant/ssh_test.rb @@ -195,16 +195,15 @@ class SshTest < Test::Unit::TestCase end should "return false if SSH connection times out" do - Net::SSH.expects(:start) - assert !@ssh.up? - end + @env.config.ssh.timeout = 0.5 - should "allow the thread the configured timeout time" do - @thread = mock("thread") - @thread.stubs(:[]) - Thread.expects(:new).returns(@thread) - @thread.expects(:join).with(@env.config.ssh.timeout).once - @ssh.up? + Net::SSH.stubs(:start).with() do + # Sleep here to artificially fake timeout + sleep 1 + true + end + + assert !@ssh.up? end should "return false if the connection is refused" do