delivery_failure_tracker_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe DeliveryFailureTracker do
  4. subject { described_class.new('http://example.com/inbox') }
  5. describe '#track_success!' do
  6. before do
  7. subject.track_failure!
  8. subject.track_success!
  9. end
  10. it 'marks URL as available again' do
  11. expect(described_class.available?('http://example.com/inbox')).to be true
  12. end
  13. it 'resets days to 0' do
  14. expect(subject.days).to be_zero
  15. end
  16. end
  17. describe '#track_failure!' do
  18. it 'marks URL as unavailable after 7 days of being called' do
  19. 6.times { |i| Redis.current.sadd('exhausted_deliveries:http://example.com/inbox', i) }
  20. subject.track_failure!
  21. expect(subject.days).to eq 7
  22. expect(described_class.unavailable?('http://example.com/inbox')).to be true
  23. end
  24. it 'repeated calls on the same day do not count' do
  25. subject.track_failure!
  26. subject.track_failure!
  27. expect(subject.days).to eq 1
  28. end
  29. end
  30. describe '.filter' do
  31. before do
  32. Redis.current.sadd('unavailable_inboxes', 'http://example.com/unavailable/inbox')
  33. end
  34. it 'removes URLs that are unavailable' do
  35. result = described_class.filter(['http://example.com/good/inbox', 'http://example.com/unavailable/inbox'])
  36. expect(result).to include('http://example.com/good/inbox')
  37. expect(result).to_not include('http://example.com/unavailable/inbox')
  38. end
  39. end
  40. describe '.track_inverse_success!' do
  41. let(:from_account) { Fabricate(:account, inbox_url: 'http://example.com/inbox', shared_inbox_url: 'http://example.com/shared/inbox') }
  42. before do
  43. Redis.current.sadd('unavailable_inboxes', 'http://example.com/inbox')
  44. Redis.current.sadd('unavailable_inboxes', 'http://example.com/shared/inbox')
  45. described_class.track_inverse_success!(from_account)
  46. end
  47. it 'marks inbox URL as available again' do
  48. expect(described_class.available?('http://example.com/inbox')).to be true
  49. end
  50. it 'marks shared inbox URL as available again' do
  51. expect(described_class.available?('http://example.com/shared/inbox')).to be true
  52. end
  53. end
  54. end