public void time_increases_with_each_failure() { Message observed = null; var message = ObjectMother.NewMessage <OutgoingMessage>(); message.Destination = new Uri("lq.tcp://localhost:5150/blah"); message.MaxAttempts = 5; var tx = _store.BeginTransaction(); _store.StoreOutgoing(tx, message); tx.Commit(); var failure = new OutgoingMessageFailure(); failure.Batch = new OutgoingMessageBatch(message.Destination, new[] { message }, new TcpClient(), new NoSecurity()); using (_errorPolicy.RetryStream.Subscribe(x => { observed = x; })) { _subject.OnNext(failure); _scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks); observed.ShouldNotBeNull("first"); observed = null; _subject.OnNext(failure); observed.ShouldBeNull("second"); _scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks); //one second isn't enough yet observed.ShouldBeNull("third"); _scheduler.AdvanceBy(TimeSpan.FromSeconds(3).Ticks); //four seconds total for second failure should match observed.ShouldNotBeNull("fourth"); } }
public void errors_in_storage_dont_end_stream() { var message = ObjectMother.NewMessage <OutgoingMessage>(); var store = Substitute.For <IMessageStore>(); store.FailedToSend(Arg.Is(message)).Throws(new Exception("bam!")); var errorPolicy = new SendingErrorPolicy(new RecordingLogger(), store, _subject, _scheduler); bool ended = false; var failure = new OutgoingMessageFailure(); failure.Batch = new OutgoingMessageBatch(message.Destination, new[] { message }, new TcpClient(), new NoSecurity()); using (errorPolicy.RetryStream.Finally(() => ended = true).Subscribe(x => { })) { _subject.OnNext(failure); _scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks); ended.ShouldBeFalse(); } }
public void message_is_observed_after_time() { Message observed = null; var message = ObjectMother.NewMessage <OutgoingMessage>(); message.Destination = new Uri("lq.tcp://localhost:5150/blah"); message.MaxAttempts = 2; var tx = _store.BeginTransaction(); _store.StoreOutgoing(tx, message); tx.Commit(); var failure = new OutgoingMessageFailure(); failure.Batch = new OutgoingMessageBatch(message.Destination, new [] { message }, new TcpClient(), new NoSecurity()); using (_errorPolicy.RetryStream.Subscribe(x => { observed = x; })) { _subject.OnNext(failure); _scheduler.AdvanceBy(TimeSpan.FromSeconds(1).Ticks); observed.ShouldNotBeNull(); } }