[InlineData(10 * 60)] // 10 min public void ReturnPeriodAfterFirstFailure(int periodInSeconds) { // Arrange var want = TimeSpan.FromSeconds(periodInSeconds); var schedule = new ExponentialBackoffConnectionSchedule(want); schedule.MarkFailure(); // Act var got = schedule.NextInterval; // Assert got.ShouldBe(want); }
[InlineData(10 * 60)] // 10 min public void RemainCappedDuringFailures(int periodInSeconds) { // Arrange var period = TimeSpan.FromSeconds(periodInSeconds); var schedule = new ExponentialBackoffConnectionSchedule(period); // Lets make sure the backoff is capped while (schedule.NextInterval != ExponentialBackoffConnectionSchedule.MaximumBackoffInterval) { schedule.MarkFailure(); } // Act for (var i = 0; i < 100000; i++) // 100 000 failures is the result of almost two years of downtime { // Assert if (schedule.NextInterval != ExponentialBackoffConnectionSchedule.MaximumBackoffInterval) { throw new Exception($"Backoff schedule transitioned from being capped ({ExponentialBackoffConnectionSchedule.MaximumBackoffInterval}) to no longer being capped ({schedule.NextInterval})"); } schedule.MarkFailure(); } }
[InlineData(10 * 60)] // 10 min public void BehaveExponentially(int periodInSeconds) { // Arrange var period = TimeSpan.FromSeconds(periodInSeconds); var schedule = new ExponentialBackoffConnectionSchedule(period); IBackoff backoff = new LinearBackoff(period); while (!(backoff is CappedBackoff)) { // Act schedule.MarkFailure(); // Assert backoff = backoff.GetNext(schedule.NextInterval); } }