diff options
Diffstat (limited to 'spec/workers')
-rw-r--r-- | spec/workers/send_base_spec.rb | 14 | ||||
-rw-r--r-- | spec/workers/send_private_spec.rb | 17 |
2 files changed, 24 insertions, 7 deletions
diff --git a/spec/workers/send_base_spec.rb b/spec/workers/send_base_spec.rb index c7961451b..7a3b77a98 100644 --- a/spec/workers/send_base_spec.rb +++ b/spec/workers/send_base_spec.rb @@ -8,13 +8,13 @@ describe Workers::SendBase do end it "increases the interval for each retry" do - expect(Workers::SendBase.new.send(:seconds_to_delay, 2)).to be >= 625 - expect(Workers::SendBase.new.send(:seconds_to_delay, 3)).to be >= 1_296 - expect(Workers::SendBase.new.send(:seconds_to_delay, 4)).to be >= 2_401 - expect(Workers::SendBase.new.send(:seconds_to_delay, 5)).to be >= 4_096 - expect(Workers::SendBase.new.send(:seconds_to_delay, 6)).to be >= 6_561 - expect(Workers::SendBase.new.send(:seconds_to_delay, 7)).to be >= 10_000 - expect(Workers::SendBase.new.send(:seconds_to_delay, 8)).to be >= 14_641 + (2..19).each do |count| + expect(Workers::SendBase.new.send(:seconds_to_delay, count)).to be >= ((count + 3)**4) + end + + # lets make some tests with explicit numbers to make sure the formula above works correctly + # and increases the delay with the expected result expect(Workers::SendBase.new.send(:seconds_to_delay, 9)).to be >= 20_736 + expect(Workers::SendBase.new.send(:seconds_to_delay, 19)).to be >= 234_256 end end diff --git a/spec/workers/send_private_spec.rb b/spec/workers/send_private_spec.rb index 622c1e93e..1817c5983 100644 --- a/spec/workers/send_private_spec.rb +++ b/spec/workers/send_private_spec.rb @@ -41,4 +41,21 @@ describe Workers::SendPrivate do Workers::SendPrivate.new.perform(sender_id, obj_str, targets, 9) }.to raise_error Workers::SendBase::MaxRetriesReached end + + it "retries contact entities 20 times" do + contact = Fabricate(:contact_entity, author: sender_id, recipient: alice.diaspora_handle) + obj_str = contact.to_s + targets = {"https://example.org/receive/user/guid" => "<xml>post</xml>"} + expect(DiasporaFederation::Federation::Sender).to receive(:private).with( + sender_id, obj_str, targets + ).and_return(targets).twice + + expect(Workers::SendPrivate).to receive(:perform_in).with(a_kind_of(Numeric), sender_id, obj_str, targets, 19) + Workers::SendPrivate.new.perform(sender_id, obj_str, targets, 18) + + expect(Workers::SendPrivate).not_to receive(:perform_in) + expect { + Workers::SendPrivate.new.perform(sender_id, obj_str, targets, 19) + }.to raise_error Workers::SendBase::MaxRetriesReached + end end |