You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.4 KiB

  1. require 'rails_helper'
  2. describe AccountCounters do
  3. let!(:account) { Fabricate(:account) }
  4. describe '#increment_count!' do
  5. it 'increments the count' do
  6. expect(account.followers_count).to eq 0
  7. account.increment_count!(:followers_count)
  8. expect(account.followers_count).to eq 1
  9. end
  10. it 'increments the count in multi-threaded an environment' do
  11. increment_by = 15
  12. wait_for_start = true
  13. threads = Array.new(increment_by) do
  14. Thread.new do
  15. true while wait_for_start
  16. account.increment_count!(:statuses_count)
  17. end
  18. end
  19. wait_for_start = false
  20. threads.each(&:join)
  21. expect(account.statuses_count).to eq increment_by
  22. end
  23. end
  24. describe '#decrement_count!' do
  25. it 'decrements the count' do
  26. account.followers_count = 15
  27. account.save!
  28. expect(account.followers_count).to eq 15
  29. account.decrement_count!(:followers_count)
  30. expect(account.followers_count).to eq 14
  31. end
  32. it 'decrements the count in multi-threaded an environment' do
  33. decrement_by = 10
  34. wait_for_start = true
  35. account.statuses_count = 15
  36. account.save!
  37. threads = Array.new(decrement_by) do
  38. Thread.new do
  39. true while wait_for_start
  40. account.decrement_count!(:statuses_count)
  41. end
  42. end
  43. wait_for_start = false
  44. threads.each(&:join)
  45. expect(account.statuses_count).to eq 5
  46. end
  47. end
  48. end