コード例 #1
0
        public void Backoff_WithFastFirstEqualToTrue_ResultIsZero()
        {
            // Arrange
            var          initialDelay = TimeSpan.FromMilliseconds(1);
            const int    retryCount   = 3;
            const double factor       = 2;
            const bool   fastFirst    = true;

            // Act
            IEnumerable <TimeSpan> result = Backoff.Exponential(initialDelay, retryCount, factor, fastFirst);

            // Assert
            result.Should().NotBeNull();
            result.Should().HaveCount(retryCount);

            bool first = true;

            foreach (TimeSpan timeSpan in result)
            {
                if (first)
                {
                    timeSpan.Should().Be(TimeSpan.FromMilliseconds(0));
                    first = false;
                }
                else
                {
                    timeSpan.Should().BeGreaterOrEqualTo(initialDelay);
                }
            }
        }
コード例 #2
0
        public void Backoff_WithRetryEqualToZero_ResultIsEmpty()
        {
            // Arrange
            var          initialDelay = TimeSpan.FromMilliseconds(1);
            const int    retryCount   = 0;
            const double factor       = 2;
            const bool   fastFirst    = false;

            // Act
            IEnumerable <TimeSpan> result = Backoff.Exponential(initialDelay, retryCount, factor, fastFirst);

            // Assert
            result.Should().NotBeNull();
            result.Should().BeEmpty();
        }
コード例 #3
0
        public void Backoff_WithFactorLessThanZero_ThrowsException()
        {
            // Arrange
            var          initialDelay = TimeSpan.FromMilliseconds(1);
            const int    retryCount   = 3;
            const double factor       = 0.99;
            const bool   fastFirst    = false;

            // Act
            Action act = () => Backoff.Exponential(initialDelay, retryCount, factor, fastFirst);

            // Assert
            act.Should().Throw <ArgumentOutOfRangeException>()
            .And.ParamName.Should().Be("factor");
        }
コード例 #4
0
        public void Backoff_ResultIsInRange()
        {
            // Arrange
            var          initialDelay = TimeSpan.FromMilliseconds(10);
            const int    retryCount   = 5;
            const double factor       = 2;
            const bool   fastFirst    = false;

            // Act
            IEnumerable <TimeSpan> result = Backoff.Exponential(initialDelay, retryCount, factor, fastFirst);

            // Assert
            result.Should().NotBeNull();
            result.Should().HaveCount(retryCount);

            TimeSpan prev = TimeSpan.Zero;

            foreach (TimeSpan timeSpan in result)
            {
                timeSpan.Should().BeGreaterThan(prev);
                prev = timeSpan;
            }
        }