mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
first pass at a wait_for helper on model
This commit is contained in:
parent
e1fdfa8144
commit
e11a1eba13
3 changed files with 15 additions and 12 deletions
|
@ -97,6 +97,17 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
def wait_for(timeout = 600, &block)
|
||||
start = Time.now
|
||||
until instance_eval(&block)
|
||||
if Time.now - start > timeout
|
||||
break
|
||||
end
|
||||
reload
|
||||
sleep(1)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def collection=(new_collection)
|
||||
|
|
|
@ -52,9 +52,7 @@ describe 'Fog::AWS::EC2::Address' do
|
|||
|
||||
it "should associate with instance to an already saved address" do
|
||||
@address.save.should be_true
|
||||
while @instance.state == 'pending'
|
||||
@instance.reload
|
||||
end
|
||||
@instance.wait_for { state == 'running' }
|
||||
@address.instance = @instance
|
||||
@address.instance_id.should == @instance.id
|
||||
end
|
||||
|
|
|
@ -49,21 +49,15 @@ describe 'Fog::AWS::EC2::Volume' do
|
|||
before(:each) do
|
||||
@instance = ec2.instances.create(:image_id => GENTOO_AMI)
|
||||
@volume = ec2.volumes.new(:availability_zone => @instance.availability_zone, :size => 1, :device => '/dev/sdz1')
|
||||
while @instance.state == 'pending'
|
||||
@instance.reload
|
||||
end
|
||||
@instance.wait_for { state == 'running' }
|
||||
end
|
||||
|
||||
after(:each) do
|
||||
@instance.destroy
|
||||
if @volume.id
|
||||
while ['attaching', 'creating'].include?(@volume.status)
|
||||
@volume.reload
|
||||
end
|
||||
@volume.wait_for { status == 'attached' }
|
||||
@volume.instance = nil
|
||||
while ['attached', 'detaching'].include?(@volume.status)
|
||||
@volume.reload
|
||||
end
|
||||
@volume.wait_for { status == 'available' }
|
||||
@volume.destroy
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue