Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/solid_queue/job/concurrency_controls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def unblock_next_blocked_job
end

def concurrency_limited?
concurrency_key.present?
concurrency_key.present? && job_class.present?
end

def blocked?
Expand Down
55 changes: 53 additions & 2 deletions test/models/solid_queue/claimed_execution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,47 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase
end
end

assert job.reload.failed?
assert_equal "new error", job.failed_execution.message
end

test "perform job with missing class fails gracefully" do
job = create_job_with_missing_class
claimed_execution = claim_job(job)

assert_difference -> { SolidQueue::ClaimedExecution.count } => -1, -> { SolidQueue::FailedExecution.count } => 1 do
assert_raises NameError do
claimed_execution.perform
end
end

assert job.reload.failed?
end

test "perform concurrency-controlled job with missing class fails gracefully" do
job = create_job_with_missing_class(concurrency_key: "test_key")
claimed_execution = claim_job(job)

assert_difference -> { SolidQueue::ClaimedExecution.count } => -1, -> { SolidQueue::FailedExecution.count } => 1 do
assert_raises NameError do
claimed_execution.perform
end
end

assert job.reload.failed?
end

test "dispatch job with missing class and concurrency key skips concurrency controls" do
job = create_job_with_missing_class(concurrency_key: "test_key")

assert_not job.concurrency_limited?

job.prepare_for_execution

assert job.reload.ready?
assert_equal 0, SolidQueue::BlockedExecution.where(job_id: job.id).count
assert_equal 0, SolidQueue::Semaphore.where(key: "test_key").count
end

test "provider_job_id is available within job execution" do
job = ProviderJobIdJob.perform_later
claimed_execution = prepare_and_claim_job job
Expand All @@ -101,8 +138,22 @@ class SolidQueue::ClaimedExecutionTest < ActiveSupport::TestCase
private
def prepare_and_claim_job(active_job, process: @process)
job = SolidQueue::Job.find_by(active_job_id: active_job.job_id)

job.prepare_for_execution
claim_job(job, process: process)
end

def create_job_with_missing_class(concurrency_key: nil)
SolidQueue::Job.create!(
queue_name: "background",
class_name: "RemovedJobClass",
active_job_id: SecureRandom.uuid,
arguments: { "job_class" => "RemovedJobClass", "arguments" => [] },
concurrency_key: concurrency_key,
scheduled_at: Time.current
)
end

def claim_job(job, process: @process)
assert_difference -> { SolidQueue::ClaimedExecution.count } => +1 do
SolidQueue::ReadyExecution.claim(job.queue_name, 1, process.id)
end
Expand Down