-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add backoff for SF operations (#776)
- Loading branch information
1 parent
862e886
commit 0fde915
Showing
6 changed files
with
127 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
# typed: true | ||
require_relative '../test_helper' | ||
|
||
module Critic::Unit | ||
class SalesforceUtilTest < Critic::UnitTest | ||
describe '#backoff' do | ||
it 'catch and retry known SF error' do | ||
count = 0 | ||
assert_nothing_raised do | ||
backoff do | ||
# raise the error only once | ||
if count == 0 | ||
count += 1 | ||
raise Restforce::ServerError.new("test") | ||
end | ||
end | ||
end | ||
assert_equal(1, count) | ||
end | ||
|
||
it 'known SF error is raised after max retries' do | ||
count = 0 | ||
assert_raise(Restforce::ServerError) do | ||
backoff do | ||
count += 1 | ||
raise Restforce::ServerError.new("test") | ||
end | ||
end | ||
assert_equal(MAX_SF_RETRY_ATTEMPTS, count) | ||
end | ||
|
||
it 'unknown Salesforce error is raised' do | ||
count = 0 | ||
assert_raise(RuntimeError) do | ||
backoff do | ||
if count == 0 | ||
count += 1 | ||
raise "Unknown error" | ||
end | ||
end | ||
end | ||
assert_equal(1, count) | ||
end | ||
end | ||
end | ||
end |