Skip to content

Commit

Permalink
change retries_remaining retry_block arg to retry_count (O-based, inc…
Browse files Browse the repository at this point in the history
…rementing)
  • Loading branch information
jrochkind committed Jan 3, 2022
1 parent 9d7ff4b commit 89ab0e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions lib/faraday/retry/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ def retry_statuses
# every retry. The block will be yielded keyword arguments:
# * env [Faraday::Env]: Request environment
# * options [Faraday::Options]: middleware options
# * retries_remaining [Integer]: how many more possible retries are
# remaining
# * retry_count [Integer]: how many retries have already occured (starts at 0)
# * exception [Exception]: exception that triggered the retry,
# will be the synthetic `Faraday::RetriableResponse` if the
# retry was triggered by something other than an exception.
Expand Down Expand Up @@ -157,7 +156,7 @@ def call(env)
@options.retry_block.call(
env: env,
options: @options,
retries_remaining: retries,
retry_count: @options.max - (retries + 1),
exception: e,
will_retry_in: sleep_amount
)
Expand Down
8 changes: 6 additions & 2 deletions spec/faraday/retry/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@
expect(retry_block_calls.first[:exception]).to be_kind_of(Errno::ETIMEDOUT)
expect(retry_block_calls.first[:options]).to be_kind_of(Faraday::Options)
expect(retry_block_calls.first[:env]).to be_kind_of(Faraday::Env)
expect(retry_block_calls.first[:will_retry_in]).to be_kind_of(Float)
expect(retry_block_calls.first[:retries_remaining]).to eq 1
expect(retry_block_calls.first[:retry_count]).to be_kind_of(Integer)
expect(retry_block_calls.first[:retry_count]).to eq 0
end

it "increments retry_count" do
expect(retry_block_calls[1][:retry_count]).to eq 1
end
end
end
Expand Down

0 comments on commit 89ab0e6

Please sign in to comment.