From b1d3cd3d14555d6d282ee96dabbd0e816cce31b4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 14 Apr 2010 22:30:46 -0700 Subject: [PATCH] SIGINT twice and vagrant will immediately exit, even if busy --- lib/vagrant/busy.rb | 7 +++++++ test/vagrant/busy_test.rb | 21 +++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/vagrant/busy.rb b/lib/vagrant/busy.rb index d7c123bb8..74b6dc174 100644 --- a/lib/vagrant/busy.rb +++ b/lib/vagrant/busy.rb @@ -45,6 +45,13 @@ module Vagrant end def wait_for_not_busy(sleeptime=5) + if @@trap_thread + logger.info "Exiting vagrant immediately!" + Thread.kill(@@trap_thread) + abort + return # for tests + end + @@trap_thread ||= Thread.new do # Wait while the app is busy loop do diff --git a/test/vagrant/busy_test.rb b/test/vagrant/busy_test.rb index e4187647d..69516476d 100644 --- a/test/vagrant/busy_test.rb +++ b/test/vagrant/busy_test.rb @@ -1,19 +1,28 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper') class BusyTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Busy + end + context "waiting for not busy" do setup do - Vagrant::Busy.reset_trap_thread! + @klass.reset_trap_thread! end should "run in a thread" do Thread.expects(:new).once.returns(nil) - Vagrant::Busy.wait_for_not_busy + @klass.wait_for_not_busy end - should "not start a thread multiple times" do - Thread.expects(:new).once.returns("foo") - Vagrant::Busy.wait_for_not_busy + should "immediately exit on second call" do + tid = "foo" + Thread.expects(:new).once.returns(tid) + @klass.wait_for_not_busy + + Thread.expects(:kill).once.with(tid) + @klass.expects(:abort).once + @klass.wait_for_not_busy end end @@ -42,7 +51,7 @@ class BusyTest < Test::Unit::TestCase should "complete the trap thread even if an exception occurs" do trap_thread = mock("trap_thread") trap_thread.expects(:join).once - Vagrant::Busy.stubs(:trap_thread).returns(trap_thread) + @klass.stubs(:trap_thread).returns(trap_thread) assert_raise Exception do Vagrant.busy do