diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-07-19 14:44:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-19 14:44:04 +0200 |
commit | 8400bee3b1960a56746196508b5e54ad9b2e0492 (patch) | |
tree | f4debdb8486cbf98be7a6cf03071500161e0548b /spec/services | |
parent | bc1f9dc24bc5d524d1b4adebadcd71984d9f11f0 (diff) |
Refactor ResolveRemoteAccountService (#4258)
* Refactor ResolveRemoteAccountService * Remove trailing whitespace * Use redis locks around critical ResolveRemoteAccountService code * Add test for race condition of lock
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/resolve_remote_account_service_spec.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/services/resolve_remote_account_service_spec.rb b/spec/services/resolve_remote_account_service_spec.rb index ad4d436ba..c51588210 100644 --- a/spec/services/resolve_remote_account_service_spec.rb +++ b/spec/services/resolve_remote_account_service_spec.rb @@ -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 |