diff options
author | Starfall <us@starfall.systems> | 2021-04-02 15:04:35 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2021-04-02 15:04:35 -0500 |
commit | aeb0f34cefd88caaaa51e8250e1f6ddde280c4bb (patch) | |
tree | 15dafdc2cdfd9e78e72e461440b593c3fc89788e /spec/models/concerns | |
parent | 0f7be4b48947a9edcbb6fb84d5d0fd9150ee0870 (diff) | |
parent | b7ec2a900251410c65ba214b50c1657209285b07 (diff) |
Merge branch 'glitch'
Diffstat (limited to 'spec/models/concerns')
-rw-r--r-- | spec/models/concerns/account_counters_spec.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/models/concerns/account_counters_spec.rb b/spec/models/concerns/account_counters_spec.rb new file mode 100644 index 000000000..4350496e7 --- /dev/null +++ b/spec/models/concerns/account_counters_spec.rb @@ -0,0 +1,60 @@ +require 'rails_helper' + +describe AccountCounters do + let!(:account) { Fabricate(:account) } + + describe '#increment_count!' do + it 'increments the count' do + expect(account.followers_count).to eq 0 + account.increment_count!(:followers_count) + expect(account.followers_count).to eq 1 + end + + it 'increments the count in multi-threaded an environment' do + increment_by = 15 + wait_for_start = true + + threads = Array.new(increment_by) do + Thread.new do + true while wait_for_start + account.increment_count!(:statuses_count) + end + end + + wait_for_start = false + threads.each(&:join) + + expect(account.statuses_count).to eq increment_by + end + end + + describe '#decrement_count!' do + it 'decrements the count' do + account.followers_count = 15 + account.save! + expect(account.followers_count).to eq 15 + account.decrement_count!(:followers_count) + expect(account.followers_count).to eq 14 + end + + it 'decrements the count in multi-threaded an environment' do + decrement_by = 10 + wait_for_start = true + + account.statuses_count = 15 + account.save! + + threads = Array.new(decrement_by) do + Thread.new do + true while wait_for_start + account.decrement_count!(:statuses_count) + end + end + + wait_for_start = false + threads.each(&:join) + + expect(account.statuses_count).to eq 5 + end + end +end |