diff --git a/lib/vagrant/busy.rb b/lib/vagrant/busy.rb deleted file mode 100644 index de670b63f..000000000 --- a/lib/vagrant/busy.rb +++ /dev/null @@ -1,79 +0,0 @@ -module Vagrant - def self.busy? - Busy.busy? - end - - def self.busy(&block) - Busy.busy(&block) - end - - class Busy - extend Vagrant::Util - - @@busy = false - @@mutex = Mutex.new - @@trap_thread = nil - - class << self - def busy? - @@busy - end - - def busy=(val) - @@busy = val - end - - def busy(&block) - @@mutex.synchronize do - begin - Signal.trap("INT") { wait_for_not_busy } - Busy.busy = true - block.call - ensure - # In the case an exception is thrown, make sure we restore - # busy back to some sane state. - Busy.busy = false - - # Make sure that the trap thread completes, if it is running - trap_thread.join if trap_thread - - # And restore the INT trap to the default - Signal.trap("INT", "DEFAULT") - end - end - 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 - break unless busy? - # logger.info "Waiting for vagrant to clean itself up..." - sleep sleeptime - end - - # Exit out of the entire script - # logger.info "Exiting vagrant..." - exit - end - end - - # Used for testing - def reset_trap_thread! - @@trap_thread = nil - end - - # Returns the trap thread - def trap_thread - @@trap_thread - end - end - end -end diff --git a/test/vagrant/busy_test.rb b/test/vagrant/busy_test.rb deleted file mode 100644 index 3886863ae..000000000 --- a/test/vagrant/busy_test.rb +++ /dev/null @@ -1,78 +0,0 @@ -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 - @klass.reset_trap_thread! - end - - should "run in a thread" do - Thread.expects(:new).once.returns(nil) - @klass.wait_for_not_busy - end - - 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 - - context "during an action in a busy block" do - should "report as busy" do - Vagrant.busy do - # Inside the block Vagrant.busy? should be true - assert Vagrant.busy? - end - - #After the block finishes Vagrant.busy? should be false - assert !Vagrant.busy? - end - - should "set busy to false upon exception and reraise the error" do - assert_raise Exception do - Vagrant.busy do - assert Vagrant.busy? - raise Exception - end - end - - assert !Vagrant.busy? - end - - should "complete the trap thread even if an exception occurs" do - trap_thread = mock("trap_thread") - trap_thread.expects(:join).once - @klass.stubs(:trap_thread).returns(trap_thread) - - assert_raise Exception do - Vagrant.busy do - raise Exception - end - end - end - - should "report busy to the outside world regardless of thread" do - Thread.new do - Vagrant.busy do - assert Vagrant.busy? - end - end - end - - should "trap INT" do - trap_seq = sequence("trap_seq") - Signal.expects(:trap).with("INT", anything).once.in_sequence(trap_seq) - Signal.expects(:trap).with("INT", "DEFAULT").once.in_sequence(trap_seq) - Vagrant.busy do; end - end - end -end