From 13cef2f834098efa74ca91764db1306bd7f0b935 Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Fri, 20 Oct 2023 11:24:20 -0700 Subject: [PATCH] Add spec to verify unhandled thread errors are reported (#1104) --- spec/integration/complex_jobs_spec.rb | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/spec/integration/complex_jobs_spec.rb b/spec/integration/complex_jobs_spec.rb index 2a688fb1a..b616146d5 100644 --- a/spec/integration/complex_jobs_spec.rb +++ b/spec/integration/complex_jobs_spec.rb @@ -8,6 +8,41 @@ before do GoodJob.capsule.restart + allow(GoodJob.on_thread_error).to receive(:call).and_call_original + end + + describe 'Job without error handler / unhandled' do + after do + # This spec will intentionally raise an error on the thread. + THREAD_ERRORS.clear + end + + specify do + stub_const "TestJob", (Class.new(ActiveJob::Base) do + def perform + raise "error" + end + end) + + TestJob.queue_adapter = async_adapter + TestJob.perform_later + + wait_until { expect(GoodJob::Job.last.finished_at).to be_present } + good_job = GoodJob::Job.last + expect(good_job).to have_attributes( + executions_count: 1, + error: "RuntimeError: error", + error_event: "unhandled" + ) + expect(good_job.executions.size).to eq 1 + expect(good_job.executions.last).to have_attributes( + error: "RuntimeError: error", + error_event: "unhandled" + ) + + expect(THREAD_ERRORS.size).to eq 1 + expect(GoodJob.on_thread_error).to have_received(:call).with(instance_of(RuntimeError)) + end end describe 'Job with retry stopped but no block' do