Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/baza-rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def home
# @yield The block to execute with retries
# @return [Object] The result of the block execution
def attempt(&)
with_retries(max_tries: @retries, rescue: TimedOut, &)
with_retries(max_tries: @retries + 1, rescue: TimedOut, &)
end

# Execute a block with retries on 429 status codes.
Expand Down
17 changes: 17 additions & 0 deletions test/test_baza_edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,23 @@ def test_download_retries_on_busy_server
end
end

# Reproduces zerocracy/baza.rb#341: BazaRb#attempt passed @retries to
# with_retries(max_tries:), so a retries: N configuration produced N-1
# retries on TimedOut while #await and #recover gave N retries on 429
# and >=499. After the fix, attempt allows @retries + 1 total tries to
# match the retry count semantics of the surrounding loops.
def test_attempt_total_tries_match_retries_plus_one
fast = BazaRb.new('example.org', 443, '000', loog: Loog::NULL, retries: 3, pause: 0)
attempts = 0
assert_raises(BazaRb::TimedOut) do
fast.__send__(:attempt) do
attempts += 1
raise(BazaRb::TimedOut, 'simulated timeout')
end
end
assert_equal(4, attempts, 'attempt must run @retries + 1 total tries on a persistent TimedOut')
end

# Reproduces zerocracy/baza.rb#289: BazaRb#download never retries on
# timeout because checked() is called outside attempt. After the fix,
# a libcurl operation_timedout on the first GET re-raises BazaRb::TimedOut
Expand Down
Loading