Remove Vagrant::Busy class. It will be making a comeback soon in a newly invented form.

This commit is contained in:
Mitchell Hashimoto 2010-07-18 01:59:01 -07:00
parent 8168ca3e86
commit bbd0f0e8cb
2 changed files with 0 additions and 157 deletions

View File

@ -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

View File

@ -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