diff options
Diffstat (limited to 'activejob/test')
-rw-r--r-- | activejob/test/cases/exceptions_test.rb | 22 | ||||
-rw-r--r-- | activejob/test/jobs/retry_job.rb | 9 |
2 files changed, 31 insertions, 0 deletions
diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb index 37bb65538a..b5328b8d6a 100644 --- a/activejob/test/cases/exceptions_test.rb +++ b/activejob/test/cases/exceptions_test.rb @@ -30,6 +30,28 @@ class ExceptionsTest < ActiveJob::TestCase end end + test "keeps the same attempts counter when several exceptions are listed in the same declaration" do + exceptions_to_raise = %w(FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo + SecondRetryableErrorOfTwo SecondRetryableErrorOfTwo) + + assert_raises SecondRetryableErrorOfTwo do + perform_enqueued_jobs do + ExceptionRetryJob.perform_later(exceptions_to_raise) + end + end + end + + test "keeps a separate attempts counter for each individual declaration" do + exceptions_to_raise = %w(FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo + DefaultsError DefaultsError) + + assert_nothing_raised do + perform_enqueued_jobs do + ExceptionRetryJob.perform_later(exceptions_to_raise) + end + end + end + test "failed retry job when exception kept occurring against defaults" do perform_enqueued_jobs do begin diff --git a/activejob/test/jobs/retry_job.rb b/activejob/test/jobs/retry_job.rb index 68dc17e16c..2d19d4c41e 100644 --- a/activejob/test/jobs/retry_job.rb +++ b/activejob/test/jobs/retry_job.rb @@ -39,3 +39,12 @@ class RetryJob < ActiveJob::Base end end end + +class ExceptionRetryJob < ActiveJob::Base + retry_on FirstRetryableErrorOfTwo, SecondRetryableErrorOfTwo, attempts: 4 + retry_on DefaultsError + + def perform(exceptions) + raise exceptions.shift.constantize.new unless exceptions.empty? + end +end |