Retryable can take multiple exceptions to retry on
This commit is contained in:
parent
0953c41446
commit
234c47a3a7
|
@ -12,7 +12,7 @@ module Vagrant
|
||||||
|
|
||||||
begin
|
begin
|
||||||
return yield
|
return yield
|
||||||
rescue opts[:on]
|
rescue *opts[:on]
|
||||||
if (opts[:tries] -= 1) > 0
|
if (opts[:tries] -= 1) > 0
|
||||||
sleep opts[:sleep].to_f if opts[:sleep]
|
sleep opts[:sleep].to_f if opts[:sleep]
|
||||||
retry
|
retry
|
||||||
|
|
|
@ -31,6 +31,18 @@ class RetryableUtilTest < Test::Unit::TestCase
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "retry on multiple exceptions given" do
|
||||||
|
proc = mock("proc")
|
||||||
|
proc.expects(:call).twice
|
||||||
|
|
||||||
|
assert_raises(StandardError) {
|
||||||
|
@klass.retryable(:tries => 2, :on => [StandardError, RuntimeError]) do
|
||||||
|
proc.call
|
||||||
|
raise StandardError
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
should "return the value of the block" do
|
should "return the value of the block" do
|
||||||
result = @klass.retryable { 7 }
|
result = @klass.retryable { 7 }
|
||||||
assert_equal 7, result
|
assert_equal 7, result
|
||||||
|
|
Loading…
Reference in New Issue