1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Updated Fog.wait_for to throw a timeout exception instead of returning false #1368

This commit is contained in:
Kyle Rames 2012-12-12 12:14:44 -06:00
parent aee9f10d1a
commit 3d306b6650
4 changed files with 20 additions and 6 deletions

View file

@ -188,11 +188,10 @@ module Fog
def soft_reboot
shutdown
# FIXME Using side effect of wait_for's (evaluated block) to detect timeouts
if wait_for(20) { ! ready? }
# Server is now down, start it up again
start
else
# We timed out
begin
wait_for(20) { ! ready? }
start
rescue Fog::Errors::Timeout => e
false
end
end

View file

@ -17,6 +17,8 @@ module Fog
class NotFound < Fog::Errors::Error; end
class LoadError < LoadError; end
class TimeoutError< Fog::Errors::Error; end
# @return [String] The error message that will be raised, if credentials cannot be found
def self.missing_credentials

View file

@ -7,7 +7,7 @@ module Fog
duration = Time.now - start
end
if duration > timeout
false
raise Errors::TimeoutError.new("The specified timeout (#{timeout} seconds) was exceeded")
else
{ :duration => duration }
end

View file

@ -0,0 +1,13 @@
Shindo.tests('Fog#wait_for', 'core') do
tests("success") do
tests('Fog#wait_for').formats(:duration => Integer) do
Fog.wait_for(1) { true }
end
end
tests("failure") do
tests('Fog#wait_for').raises(Fog::Errors::TimeoutError) do
Fog.wait_for(2) { false }
end
end
end