I have this job ia Rails 5.1 app. Don't mind retries_count
(that is defined inside the CountRetries concern). The idea is that the job is retried 5 times if a CustomError
is raised, with 10 minutes between retries.
class MyOwnJob < ApplicationJob include CountRetries queue_as :default def perform(argument) begin # Do some stuff rescue CustomError if retries_count < 5 retry_job wait: 10.minutes else logger.error "Job retries exhausted" end end end end
The following code will test that it enqueues one retry:
require 'test_helper' class MyOwnJobTest < ActiveJob::TestCase test "enqueues one retry after failure" do # Stub a CustomError MyOwnJob.perform_now x assert_enqueued_jobs 1, only: MyOwnJob end end
How can I test the "retry 5 times, 10 minutes between retries" behavior using ministest/assertions?
0 comments:
Post a Comment