2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-04-29 13:55:43 +02:00
|
|
|
RSpec.shared_examples 'a job retrying transient errors' do |job_class = described_class|
|
2023-11-10 14:24:28 +01:00
|
|
|
ExconErrorJob = Class.new(job_class) do
|
|
|
|
def perform
|
|
|
|
raise Excon::Error::InternalServerError, 'msg'
|
|
|
|
end
|
|
|
|
end if !defined?(ExconErrorJob)
|
|
|
|
|
|
|
|
StandardErrorJob = Class.new(job_class) do
|
|
|
|
def perform
|
|
|
|
raise StandardError
|
2021-04-29 13:55:43 +02:00
|
|
|
end
|
2023-11-10 14:24:28 +01:00
|
|
|
end if !defined?(StandardErrorJob)
|
2021-04-29 13:55:43 +02:00
|
|
|
|
2023-11-10 14:24:28 +01:00
|
|
|
context 'when a transient network error is raised' do
|
2021-04-29 13:55:43 +02:00
|
|
|
it 'makes 5 attempts before raising the exception up' do
|
|
|
|
assert_performed_jobs 5 do
|
|
|
|
ExconErrorJob.perform_later rescue Excon::Error::InternalServerError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when another type of error is raised' do
|
|
|
|
it 'makes only 1 attempt before raising the exception up' do
|
|
|
|
assert_performed_jobs 1 do
|
|
|
|
StandardErrorJob.perform_later rescue StandardError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|