Refactor ResolveRemoteAccountService (#4258)
* Refactor ResolveRemoteAccountService * Remove trailing whitespace * Use redis locks around critical ResolveRemoteAccountService code * Add test for race condition of lock
This commit is contained in:
@ -68,4 +68,27 @@ RSpec.describe ResolveRemoteAccountService do
|
||||
expect(account.domain).to eq 'localdomain.com'
|
||||
expect(account.remote_url).to eq 'https://webdomain.com/users/foo.atom'
|
||||
end
|
||||
|
||||
it 'processes one remote account at a time using locks' do
|
||||
wait_for_start = true
|
||||
fail_occurred = false
|
||||
return_values = []
|
||||
|
||||
threads = Array.new(5) do
|
||||
Thread.new do
|
||||
true while wait_for_start
|
||||
begin
|
||||
return_values << subject.call('foo@localdomain.com')
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
fail_occurred = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
wait_for_start = false
|
||||
threads.each(&:join)
|
||||
|
||||
expect(fail_occurred).to be false
|
||||
expect(return_values).to_not include(nil)
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user