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:
parent
aee9f10d1a
commit
3d306b6650
4 changed files with 20 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
13
tests/core/wait_for_tests.rb
Normal file
13
tests/core/wait_for_tests.rb
Normal 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
|
Loading…
Add table
Reference in a new issue