diff --git a/app/models/solid_queue/claimed_execution.rb b/app/models/solid_queue/claimed_execution.rb index d4abf45a..c2b13909 100644 --- a/app/models/solid_queue/claimed_execution.rb +++ b/app/models/solid_queue/claimed_execution.rb @@ -64,6 +64,7 @@ def perform finished else failed_with(result.error) + raise result.error end ensure job.unblock_next_blocked_job diff --git a/test/models/solid_queue/claimed_execution_test.rb b/test/models/solid_queue/claimed_execution_test.rb index 226dad77..4e99fd04 100644 --- a/test/models/solid_queue/claimed_execution_test.rb +++ b/test/models/solid_queue/claimed_execution_test.rb @@ -22,7 +22,9 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase job = claimed_execution.job assert_difference -> { SolidQueue::ClaimedExecution.count } => -1, -> { SolidQueue::FailedExecution.count } => 1 do - claimed_execution.perform + assert_raises RuntimeError do + claimed_execution.perform + end end assert_not job.reload.finished? @@ -37,10 +39,12 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase test "job failures are reported via Rails error subscriber" do subscriber = ErrorBuffer.new - with_error_subscriber(subscriber) do - claimed_execution = prepare_and_claim_job RaisingJob.perform_later(RuntimeError, "B") + assert_raises RuntimeError do + with_error_subscriber(subscriber) do + claimed_execution = prepare_and_claim_job RaisingJob.perform_later(RuntimeError, "B") - claimed_execution.perform + claimed_execution.perform + end end assert_equal 1, subscriber.errors.count diff --git a/test/unit/worker_test.rb b/test/unit/worker_test.rb index 3523e4a1..09999808 100644 --- a/test/unit/worker_test.rb +++ b/test/unit/worker_test.rb @@ -67,6 +67,23 @@ class WorkerTest < ActiveSupport::TestCase SolidQueue.on_thread_error = original_on_thread_error end + test "errors on claimed executions are reported via Rails error subscriber" do + subscriber = ErrorBuffer.new + Rails.error.subscribe(subscriber) + + RaisingJob.perform_later(RuntimeError, "B") + + @worker.start + + wait_for_jobs_to_finish_for(1.second) + @worker.wake_up + + assert_equal 1, subscriber.errors.count + assert_equal "This is a RuntimeError exception", subscriber.messages.first + ensure + Rails.error.unsubscribe(subscriber) if Rails.error.respond_to?(:unsubscribe) + end + test "claim and process more enqueued jobs than the pool size allows to process at once" do 5.times do |i| StoreResultJob.perform_later(:paused, pause: 0.1.second)