Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# HEAD

- Fix: Do not count skipped sleep intervals against `max_elapsed_time` when `sleep_disabled` is true.
- Add `override` and `reset_override` APIs to force retry settings over local call options when needed (for example, test short-circuiting).

## 3.4.1
Expand Down
3 changes: 2 additions & 1 deletion lib/retriable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def execute_tries( # rubocop:disable Metrics/ParameterLists
interval = intervals[index]
call_on_retry(on_retry, e, try, elapsed_time.call, interval)

raise unless can_retry?(try, tries, elapsed_time.call, interval, max_elapsed_time)
elapsed_interval = sleep_disabled == true ? 0 : interval
raise unless can_retry?(try, tries, elapsed_time.call, elapsed_interval, max_elapsed_time)

sleep interval if sleep_disabled != true
end
Expand Down
12 changes: 12 additions & 0 deletions spec/retriable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,18 @@ def increment_tries_with_exception(exception_class = nil)
expect(@tries).to eq(2)
end

it "does not count skipped sleep intervals against max elapsed time" do
allow(Process).to receive(:clock_gettime).with(Process::CLOCK_MONOTONIC).and_return(0.0)

expect do
described_class.retriable(tries: 3, base_interval: 1.0, rand_factor: 0.0, max_elapsed_time: 0.1) do
increment_tries_with_exception
end
end.to raise_error(StandardError)

expect(@tries).to eq(3)
end

it "retries up to tries limit when max_elapsed_time is nil" do
expect do
described_class.retriable(tries: 4, max_elapsed_time: nil) { increment_tries_with_exception }
Expand Down