Skip to content

Commit

Permalink
Add spec to verify unhandled thread errors are reported (#1104)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon authored Oct 20, 2023
1 parent 575d7b0 commit 13cef2f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions spec/integration/complex_jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 13cef2f

Please sign in to comment.