@@ -67,6 +67,9 @@ class FailedJobWithCron < FailedJob
6767 sentry_monitor_check_ins slug : "failed_job" , monitor_config : Sentry ::Cron ::MonitorConfig . from_crontab ( "5 * * * *" )
6868end
6969
70+ class FailedJobWithRetryOn < FailedJob
71+ retry_on StandardError , attempts : 3 , wait : 0
72+ end
7073
7174RSpec . describe "without Sentry initialized" do
7275 it "runs job" do
@@ -79,6 +82,9 @@ class FailedJobWithCron < FailedJob
7982end
8083
8184RSpec . describe "ActiveJob integration" do
85+ include ActiveJob ::TestHelper
86+ include ActiveSupport ::Testing ::TaggedLogging
87+
8288 before do
8389 make_basic_app
8490 end
@@ -318,7 +324,6 @@ def perform(event, hint)
318324
319325 it "does not trigger sentry and re-raises" do
320326 expect { FailedJob . perform_now } . to raise_error ( FailedJob ::TestError )
321-
322327 expect ( transport . events . size ) . to eq ( 0 )
323328 end
324329 end
@@ -386,4 +391,42 @@ def perform(event, hint)
386391 end
387392 end
388393 end
394+
395+ describe "active_job_report_after_job_retries" do
396+ before do
397+ allow ( Sentry ::Rails ::ActiveJobExtensions ::SentryReporter )
398+ . to receive ( :capture_exception )
399+ . and_call_original
400+ end
401+ context "when active_job_report_after_job_retries is false" do
402+ it "reports 3 exceptions" do
403+ assert_performed_jobs 3 do
404+ FailedJobWithRetryOn . perform_later rescue nil
405+ end
406+
407+ expect ( Sentry ::Rails ::ActiveJobExtensions ::SentryReporter )
408+ . to have_received ( :capture_exception )
409+ . exactly ( 3 ) . times
410+ end
411+ end
412+ context "when active_job_report_after_job_retries is true" do
413+ before do
414+ Sentry . configuration . rails . active_job_report_after_job_retries = true
415+ end
416+
417+ after do
418+ Sentry . configuration . rails . active_job_report_after_job_retries = false
419+ end
420+
421+ it "reports 1 exception" do
422+ assert_performed_jobs 3 do
423+ FailedJobWithRetryOn . perform_later rescue nil
424+ end
425+
426+ expect ( Sentry ::Rails ::ActiveJobExtensions ::SentryReporter )
427+ . to have_received ( :capture_exception )
428+ . exactly ( 1 ) . times
429+ end
430+ end
431+ end
389432end
0 commit comments