Esempio n. 1
0
        [InlineData(10 * 60)]  // 10 min
        public void ReturnPeriodDuringSuccess(int periodInSeconds)
        {
            // Arrange
            var want     = TimeSpan.FromSeconds(periodInSeconds);
            var schedule = new ExponentialBackoffConnectionSchedule(want);

            // Act
            var got = schedule.NextInterval;

            // Assert
            got.ShouldBe(want);
        }
Esempio n. 2
0
        [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);
        }
Esempio n. 3
0
        [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);
            }
        }
Esempio n. 4
0
        [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();
            }
        }