Add common ThreadingHelper
module for specs (#29116)
This commit is contained in:
parent
dbafec88e5
commit
95da28d201
6 changed files with 40 additions and 57 deletions
|
@ -219,27 +219,19 @@ RSpec.describe ResolveAccountService, type: :service do
|
|||
end
|
||||
|
||||
it 'processes one remote account at a time using locks' do
|
||||
wait_for_start = true
|
||||
fail_occurred = false
|
||||
return_values = Concurrent::Array.new
|
||||
|
||||
threads = Array.new(5) do
|
||||
Thread.new do
|
||||
true while wait_for_start
|
||||
|
||||
begin
|
||||
return_values << described_class.new.call('foo@ap.example.com')
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
fail_occurred = true
|
||||
ensure
|
||||
RedisConfiguration.pool.checkin if Thread.current[:redis]
|
||||
end
|
||||
multi_threaded_execution(5) do
|
||||
begin
|
||||
return_values << described_class.new.call('foo@ap.example.com')
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
fail_occurred = true
|
||||
ensure
|
||||
RedisConfiguration.pool.checkin if Thread.current[:redis]
|
||||
end
|
||||
end
|
||||
|
||||
wait_for_start = false
|
||||
threads.each(&:join)
|
||||
|
||||
expect(fail_occurred).to be false
|
||||
expect(return_values).to_not include(nil)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue