aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/cases
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2016-07-29 13:54:55 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2016-07-29 13:54:55 -0700
commit8b5c04e423cbfd90a15ed6fbab3f111803bc6544 (patch)
treee96cb1cbcf2a7732c97a01a345dc384321505f92 /activejob/test/cases
parent3916656f8e9700eb5f1cfc441ff66e1f12173683 (diff)
downloadrails-8b5c04e423cbfd90a15ed6fbab3f111803bc6544.tar.gz
rails-8b5c04e423cbfd90a15ed6fbab3f111803bc6544.tar.bz2
rails-8b5c04e423cbfd90a15ed6fbab3f111803bc6544.zip
Add retry_on/discard_on for better exception handling
Diffstat (limited to 'activejob/test/cases')
-rw-r--r--activejob/test/cases/exceptions_test.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb
new file mode 100644
index 0000000000..42d4dd78a5
--- /dev/null
+++ b/activejob/test/cases/exceptions_test.rb
@@ -0,0 +1,47 @@
+require 'helper'
+require 'jobs/retry_job'
+
+class ExceptionsTest < ActiveSupport::TestCase
+ setup do
+ JobBuffer.clear
+ end
+
+ test "successfully retry job throwing exception against defaults" do
+ RetryJob.perform_later 'SeriousError', 5
+
+ assert_equal [
+ "Raised SeriousError for the 1st time",
+ "Raised SeriousError for the 2nd time",
+ "Raised SeriousError for the 3rd time",
+ "Raised SeriousError for the 4th time",
+ "Successfully completed job" ], JobBuffer.values
+ end
+
+ test "successfully retry job throwing exception against higher limit" do
+ RetryJob.perform_later 'VerySeriousError', 9
+ assert_equal 9, JobBuffer.values.count
+ end
+
+ test "failed retry job when exception kept occurring against defaults" do
+ begin
+ RetryJob.perform_later 'SeriousError', 6
+ assert_equal "Raised SeriousError for the 5th time", JobBuffer.last_value
+ rescue SeriousError
+ pass
+ end
+ end
+
+ test "failed retry job when exception kept occurring against higher limit" do
+ begin
+ RetryJob.perform_later 'VerySeriousError', 11
+ assert_equal "Raised VerySeriousError for the 10th time", JobBuffer.last_value
+ rescue SeriousError
+ pass
+ end
+ end
+
+ test "discard job" do
+ RetryJob.perform_later 'NotSeriousError', 2
+ assert_equal "Raised NotSeriousError for the 1st time", JobBuffer.last_value
+ end
+end