Skip to content

Commit

Permalink
Fix retry logic (#67)
Browse files Browse the repository at this point in the history
* fix retry logic and add a test for it

* update changelog and version

* kill extra line

* ensure the configuration always gets reset back
  • Loading branch information
etokarev authored Jan 10, 2024
1 parent 7aeb5c7 commit 3797bfa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.3.1 (Jan 9, 2024)

* Fix a bug with the retry logic in `with_response_handling` resulting in performing one more retry than expected .

*Eugene Tokarev*

## 1.3 (Jan 8, 2024)

* Introduces :login_host configuration attribute used to set up OAuth2::Client. Please note, this will result Procore::Client use `https://login.procore.com/oauth/token` instead of `https://api.procore.com/oauth/token` for auth token generation.
Expand Down
2 changes: 1 addition & 1 deletion lib/procore/requestable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def with_response_handling(request_body: nil)
begin
result = yield
rescue *HTTP_EXCEPTIONS => e
if retries <= Procore.configuration.max_retries
if retries < Procore.configuration.max_retries
retries += 1
sleep 1.5**retries
retry
Expand Down
2 changes: 1 addition & 1 deletion lib/procore/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Procore
VERSION = "1.3".freeze
VERSION = "1.3.1".freeze
end
20 changes: 20 additions & 0 deletions test/procore/requestable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,24 @@ def test_error_body
assert_equal({ "errors" => "Unauthorized" }, e.response.body)
end
end

def test_no_retry_logic
# Disable retries
max_retries_old = Procore.configuration.max_retries

begin
Procore.configuration.max_retries = 0
stub_request(:get, "http://test.com/rest/v1.0/retry_test")
.to_raise(RestClient::Exceptions::Timeout)

# Attempt to perform the request and assert the correct exception is raised
assert_raises(Procore::APIConnectionError) do
Request.new(token: "token").get("retry_test")
end

assert_requested :get, "http://test.com/rest/v1.0/retry_test", times: 1
ensure
Procore.configuration.max_retries = max_retries_old
end
end
end

0 comments on commit 3797bfa

Please sign in to comment.