Skip to content

Commit e9661b0

Browse files
committed
Call previous on_thread_error when silencing exceptions
For unsilenced exceptions, this was calling the `silent_on_thread_error_for` replacement because it was being assigned before calling it.
1 parent f905adc commit e9661b0

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

test/integration/jobs_lifecycle_test.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
class JobsLifecycleTest < ActiveSupport::TestCase
66
setup do
7-
SolidQueue.on_thread_error = silent_on_thread_error_for([ ExpectedTestError, RaisingJob::DefaultError ])
7+
@_on_thread_error = SolidQueue.on_thread_error
8+
SolidQueue.on_thread_error = silent_on_thread_error_for([ ExpectedTestError, RaisingJob::DefaultError ], @_on_thread_error)
89
@worker = SolidQueue::Worker.new(queues: "background", threads: 3)
910
@dispatcher = SolidQueue::Dispatcher.new(batch_size: 10, polling_interval: 0.2)
1011
end
1112

1213
teardown do
13-
SolidQueue.on_thread_error = @on_thread_error
14+
SolidQueue.on_thread_error = @_on_thread_error
1415
@worker.stop
1516
@dispatcher.stop
1617

test/test_helper.rb

+7-12
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ class ActiveSupport::TestCase
3131
include ConfigurationTestHelper, ProcessesTestHelper, JobsTestHelper
3232

3333
setup do
34-
# Could be cleaner with one several minitest gems, but didn't want to add new dependency
3534
@_on_thread_error = SolidQueue.on_thread_error
36-
SolidQueue.on_thread_error = silent_on_thread_error_for(ExpectedTestError)
35+
SolidQueue.on_thread_error = silent_on_thread_error_for(ExpectedTestError, @_on_thread_error)
3736
end
3837

3938
teardown do
@@ -84,21 +83,17 @@ def skip_active_record_query_cache(&block)
8483
# @param [Exception, Array<Exception>] expected an Exception or an array of Exceptions to ignore
8584
# @yield Executes the provided block with specified exception(s) silenced
8685
def silence_on_thread_error_for(expected, &block)
87-
SolidQueue.with(on_thread_error: silent_on_thread_error_for(expected)) do
86+
current_proc = SolidQueue.on_thread_error
87+
88+
SolidQueue.with(on_thread_error: silent_on_thread_error_for(expected, current_proc)) do
8889
block.call
8990
end
9091
end
9192

92-
# Does not call on_thread_error for expected exceptions
93-
# @param [Exception, Array<Exception>] expected an Exception or an array of Exceptions to ignore
94-
def silent_on_thread_error_for(expected)
95-
current_proc = SolidQueue.on_thread_error
96-
93+
def silent_on_thread_error_for(exceptions, on_thread_error)
9794
->(exception) do
98-
expected_exceptions = Array(expected)
99-
100-
unless expected_exceptions.any? { exception.instance_of?(_1) }
101-
current_proc.call(exception)
95+
unless Array(exceptions).any? { |e| exception.instance_of?(e) }
96+
on_thread_error.call(exception)
10297
end
10398
end
10499
end

0 commit comments

Comments
 (0)