public void KeepsTransmissionSenderPausedWhenAdditionalTransmissionsFail() { var transmitter = new StubTransmitter(); var policy = new TestableErrorHandlingTransmissionPolicy(); policy.Initialize(transmitter); policy.BackOffTime = TimeSpan.FromMilliseconds(10); transmitter.OnTransmissionSent(new TransmissionProcessedEventArgs(new StubTransmission(), CreateException(statusCode: 408))); policy.BackOffTime = TimeSpan.FromMilliseconds(50); transmitter.OnTransmissionSent(new TransmissionProcessedEventArgs(new StubTransmission(), CreateException(statusCode: 408))); Thread.Sleep(TimeSpan.FromMilliseconds(30)); Assert.Equal(0, policy.MaxSenderCapacity); }
public void StopsTransmissionSendingWhenTransmissionTimesOut() { var policyApplied = new AutoResetEvent(false); var transmitter = new StubTransmitter(); transmitter.OnApplyPolicies = () => { policyApplied.Set(); }; var policy = new TestableErrorHandlingTransmissionPolicy(); policy.Initialize(transmitter); policy.BackOffTime = TimeSpan.FromSeconds(10); transmitter.OnTransmissionSent(new TransmissionProcessedEventArgs(new StubTransmission(), CreateException(statusCode: 408))); Assert.True(policyApplied.WaitOne(100)); Assert.Equal(0, policy.MaxSenderCapacity); }
public void RetriesFailedTransmissionInfinitely() { Transmission enqueuedTransmission = null; var transmitter = new StubTransmitter(); transmitter.OnEnqueue = transmission => { enqueuedTransmission = transmission; }; var policy = new TestableErrorHandlingTransmissionPolicy(); policy.BackOffTime = TimeSpan.FromMilliseconds(10); policy.Initialize(transmitter); var failedTransmission = new StubTransmission(); transmitter.OnTransmissionSent(new TransmissionProcessedEventArgs(failedTransmission, CreateException(statusCode: 408))); transmitter.OnTransmissionSent(new TransmissionProcessedEventArgs(failedTransmission, CreateException(statusCode: 408))); transmitter.OnTransmissionSent(new TransmissionProcessedEventArgs(failedTransmission, CreateException(statusCode: 408))); Assert.Same(failedTransmission, enqueuedTransmission); }