diff options
author | Rosa Gutierrez <rosa.ge@gmail.com> | 2019-01-05 01:54:38 +0100 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2019-01-05 13:54:38 +1300 |
commit | 88349cee3cb8f7bba662232fbc444eeebc8bb227 (patch) | |
tree | eb0cf4553e1226a708373ebd2b042f476af83b05 /activejob/test/cases/exceptions_test.rb | |
parent | 8a23a0e8c20c0cccf0073906d7dd7f809bfa836d (diff) | |
download | rails-88349cee3cb8f7bba662232fbc444eeebc8bb227.tar.gz rails-88349cee3cb8f7bba662232fbc444eeebc8bb227.tar.bz2 rails-88349cee3cb8f7bba662232fbc444eeebc8bb227.zip |
Support in-flight jobs stored before individual execution counters for `retry_on` (#34731)
Also, make tests and examples for individual execution counters
clearer, as it wasn't entierly clear what would happen in this case:
```
retry_on CustomException, OtherException, attempts: 3
```
The job would be retried at most 3 times in total, for both
CustomException and OtherException. To have the job retry 3 times at
most for each exception individually, the following retry_on
declarations are necessary:
```
retry_on CustomException, attempts: 3
retry_on OtherException, attempts: 3
```
Diffstat (limited to 'activejob/test/cases/exceptions_test.rb')
-rw-r--r-- | activejob/test/cases/exceptions_test.rb | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb index 67327e0bbd..cac48cb6cb 100644 --- a/activejob/test/cases/exceptions_test.rb +++ b/activejob/test/cases/exceptions_test.rb @@ -30,25 +30,44 @@ class ExceptionsTest < ActiveJob::TestCase end end - test "keeps the same attempts counter when several exceptions are listed in the same declaration" do + test "keeps the same attempts counter for several exceptions listed in the same retry_on 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) + RetryJob.perform_later(exceptions_to_raise, 5) end + + assert_equal [ + "Raised FirstRetryableErrorOfTwo for the 1st time", + "Raised FirstRetryableErrorOfTwo for the 2nd time", + "Raised FirstRetryableErrorOfTwo for the 3rd time", + "Raised SecondRetryableErrorOfTwo for the 4th time", + "Raised SecondRetryableErrorOfTwo for the 5th time", + ], JobBuffer.values end end - test "keeps a separate attempts counter for each individual declaration" do - exceptions_to_raise = %w(FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo - DefaultsError DefaultsError) + test "keeps a separate attempts counter for each individual retry_on declaration" do + exceptions_to_raise = %w(DefaultsError DefaultsError DefaultsError DefaultsError + FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo) assert_nothing_raised do perform_enqueued_jobs do - ExceptionRetryJob.perform_later(exceptions_to_raise) + RetryJob.perform_later(exceptions_to_raise, 10) end + + assert_equal [ + "Raised DefaultsError for the 1st time", + "Raised DefaultsError for the 2nd time", + "Raised DefaultsError for the 3rd time", + "Raised DefaultsError for the 4th time", + "Raised FirstRetryableErrorOfTwo for the 5th time", + "Raised FirstRetryableErrorOfTwo for the 6th time", + "Raised FirstRetryableErrorOfTwo for the 7th time", + "Successfully completed job" + ], JobBuffer.values end end |