@@ -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" , type : :job do
7275 it "runs job" do
@@ -318,7 +321,6 @@ def perform(event, hint)
318321
319322 it "does not trigger sentry and re-raises" do
320323 expect { FailedJob . perform_now } . to raise_error ( FailedJob ::TestError )
321-
322324 expect ( transport . events . size ) . to eq ( 0 )
323325 end
324326 end
@@ -386,4 +388,42 @@ def perform(event, hint)
386388 end
387389 end
388390 end
391+
392+ describe "active_job_report_after_job_retries" do
393+ before do
394+ allow ( Sentry ::Rails ::ActiveJobExtensions ::SentryReporter )
395+ . to receive ( :capture_exception )
396+ . and_call_original
397+ end
398+ context "when active_job_report_after_job_retries is false" do
399+ it "reports 3 exceptions" do
400+ assert_performed_jobs 3 do
401+ FailedJobWithRetryOn . perform_later rescue nil
402+ end
403+
404+ expect ( Sentry ::Rails ::ActiveJobExtensions ::SentryReporter )
405+ . to have_received ( :capture_exception )
406+ . exactly ( 3 ) . times
407+ end
408+ end
409+ context "when active_job_report_after_job_retries is true" do
410+ before do
411+ Sentry . configuration . rails . active_job_report_after_job_retries = true
412+ end
413+
414+ after do
415+ Sentry . configuration . rails . active_job_report_after_job_retries = false
416+ end
417+
418+ it "reports 1 exception" do
419+ assert_performed_jobs 3 do
420+ FailedJobWithRetryOn . perform_later rescue nil
421+ end
422+
423+ expect ( Sentry ::Rails ::ActiveJobExtensions ::SentryReporter )
424+ . to have_received ( :capture_exception )
425+ . exactly ( 1 ) . times
426+ end
427+ end
428+ end
389429end
0 commit comments