From ddfc2c9e098a75081ade1ce534e5fe04184cd291 Mon Sep 17 00:00:00 2001 From: edmoffo Date: Mon, 1 Jun 2026 00:23:00 +0000 Subject: [PATCH] fix: #341 align attempt retry count with await and recover with_retries treats max_tries as the total attempt count, so passing @retries gave @retries - 1 retries on TimedOut while #await and #recover gave @retries retries on 429 and >=499. Pass @retries + 1 to with_retries so the three retry layers all interpret the constructor's retries: kwarg as the retry count, matching the YARD on line 58. A new test_attempt_total_tries_match_retries_plus_one in test/test_baza_edge.rb pins the count at @retries + 1 total tries on a persistent TimedOut. --- lib/baza-rb.rb | 2 +- test/test_baza_edge.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/baza-rb.rb b/lib/baza-rb.rb index b7fe563..1c6f2e2 100644 --- a/lib/baza-rb.rb +++ b/lib/baza-rb.rb @@ -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. diff --git a/test/test_baza_edge.rb b/test/test_baza_edge.rb index 338462b..b1996b3 100644 --- a/test/test_baza_edge.rb +++ b/test/test_baza_edge.rb @@ -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