0
0
Fork 0

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:
Eugen Rochko 2017-07-19 14:44:04 +02:00 committed by GitHub
parent bc1f9dc24b
commit 8400bee3b1
4 changed files with 141 additions and 58 deletions

View file

@ -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