Skip to content

Commit 53b6189

Browse files
authored
Merge pull request #221 from rails/handle-nil-limit
Handle case of concurrency limit not being set in Semaphore
2 parents 34fe429 + f2663c8 commit 53b6189

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

app/models/solid_queue/semaphore.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def expires_at
7070
end
7171

7272
def limit
73-
job.concurrency_limit
73+
job.concurrency_limit || 1
7474
end
7575
end
7676
end

test/integration/instrumentation_test.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class InstrumentationTest < ActiveSupport::TestCase
1010
travel_to 2.days.from_now
1111
dispatcher = SolidQueue::Dispatcher.new(polling_interval: 0.1, batch_size: 10).tap(&:start)
1212

13-
wait_while_with_timeout(0.5.seconds) { SolidQueue::ScheduledExecution.any? }
13+
wait_while_with_timeout!(0.5.seconds) { SolidQueue::ScheduledExecution.any? }
1414
dispatcher.stop
1515
end
1616

@@ -19,13 +19,13 @@ class InstrumentationTest < ActiveSupport::TestCase
1919
end
2020

2121
test "stopping a worker with claimed executions emits release_claimed events" do
22-
StoreResultJob.perform_later(42, pause: SolidQueue.shutdown_timeout + 10.second)
22+
StoreResultJob.perform_later(42, pause: SolidQueue.shutdown_timeout + 100.second)
2323
process = nil
2424

2525
events = subscribed(/release.*_claimed\.solid_queue/) do
2626
worker = SolidQueue::Worker.new.tap(&:start)
2727

28-
wait_while_with_timeout(3.seconds) { SolidQueue::ReadyExecution.any? }
28+
wait_while_with_timeout!(3.seconds) { SolidQueue::ReadyExecution.any? }
2929
process = SolidQueue::Process.last
3030

3131
worker.stop
@@ -54,12 +54,12 @@ class InstrumentationTest < ActiveSupport::TestCase
5454
end
5555

5656
test "starting and stopping a worker emits register_process and deregister_process events" do
57-
StoreResultJob.perform_later(42, pause: SolidQueue.shutdown_timeout + 10.second)
57+
StoreResultJob.perform_later(42, pause: SolidQueue.shutdown_timeout + 100.second)
5858
process = nil
5959

6060
events = subscribed(/(register|deregister)_process\.solid_queue/) do
6161
worker = SolidQueue::Worker.new.tap(&:start)
62-
wait_while_with_timeout(3.seconds) { SolidQueue::ReadyExecution.any? }
62+
wait_while_with_timeout!(3.seconds) { SolidQueue::ReadyExecution.any? }
6363

6464
process = SolidQueue::Process.last
6565

test/test_helper.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@ def wait_for_process_termination_with_timeout(pid, timeout: 10, exitstatus: 0)
8585
end
8686

8787
def wait_while_with_timeout(timeout, &block)
88+
wait_while_with_timeout!(timeout, &block)
89+
rescue Timeout::Error
90+
end
91+
92+
def wait_while_with_timeout!(timeout, &block)
8893
Timeout.timeout(timeout) do
8994
skip_active_record_query_cache do
9095
while block.call
9196
sleep 0.05
9297
end
9398
end
9499
end
95-
rescue Timeout::Error
96100
end
97101

98102
def signal_process(pid, signal, wait: nil)

0 commit comments

Comments
 (0)