Sleep for a second on vagrant destroy if the boot mode is GUI. Required to wait for GUI to clean itself up.

This commit is contained in:
Mitchell Hashimoto 2010-04-10 17:46:42 -07:00
parent 90d2ec5ab3
commit 4d3f929b3f
4 changed files with 34 additions and 4 deletions

View File

@ -6,6 +6,13 @@ module Vagrant
@runner.add_action(Halt) if @runner.vm.running?
@runner.add_action(Destroy)
end
def after_halt
# This sleep is necessary to wait for the GUI to clean itself up.
# There appears to be nothing in the API that does this "wait"
# for us.
Kernel.sleep(1) if @runner.env.config.vm.boot_mode == "gui"
end
end
end
end

View File

@ -5,8 +5,10 @@ module Vagrant
def execute!
raise ActionException.new(:vm_not_running) unless @runner.vm.running?
logger.info "Forcing shutdown of VM..."
@runner.vm.stop
@runner.invoke_around_callback(:halt) do
logger.info "Forcing shutdown of VM..."
@runner.vm.stop
end
end
end
end

View File

@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper')
class DownActionTest < Test::Unit::TestCase
setup do
@mock_vm, @vm, @action = mock_action(Vagrant::Actions::VM::Down)
@runner, @vm, @action = mock_action(Vagrant::Actions::VM::Down)
end
context "preparing" do
@ -13,7 +13,7 @@ class DownActionTest < Test::Unit::TestCase
def setup_action_expectations(order)
default_seq = sequence("default_seq")
order.each do |action|
@mock_vm.expects(:add_action).with(action).once.in_sequence(default_seq)
@runner.expects(:add_action).with(action).once.in_sequence(default_seq)
end
end
@ -28,4 +28,18 @@ class DownActionTest < Test::Unit::TestCase
@action.prepare
end
end
context "after halting" do
should "sleep if boot mode is GUI" do
@runner.env.config.vm.boot_mode = "gui"
Kernel.expects(:sleep).once
@action.after_halt
end
should "not sleep if boot mode is anything else" do
@runner.env.config.vm.boot_mode = "vrdp"
Kernel.expects(:sleep).never
@action.after_halt
end
end
end

View File

@ -10,6 +10,13 @@ class HaltActionTest < Test::Unit::TestCase
@vm.stubs(:running?).returns(true)
end
should "invoke the 'halt' around callback" do
halt_seq = sequence("halt_seq")
@runner.expects(:invoke_around_callback).with(:halt).once.in_sequence(halt_seq).yields
@vm.expects(:stop).in_sequence(halt_seq)
@action.execute!
end
should "force the VM to stop" do
@vm.expects(:stop).once
@action.execute!