예제 #1
0
        public void TestRetryFinishesIfSuccessful()
        {
            Func <TimeSpan> retryStrategy = () => {
                return(TimeSpan.FromMilliseconds(1));
            };

            var target = new RetryTarget();

            RetryHelper.Retry(() => target.TargetActionThrows5Times(), retryStrategy, 20);
            Assert.Equal(6, target.Calls);
        }
예제 #2
0
        public void TestRetryWithFixedRetryBackoff()
        {
            Func <TimeSpan> retryStrategy = () => {
                return(TimeSpan.FromMilliseconds(1));
            };

            var target = new RetryTarget();

            try
            {
                RetryHelper.Retry(() => target.TargetActionThrows(), retryStrategy, 7);
            }
            catch
            {
                Assert.Equal(7, target.Calls);
            }
        }
예제 #3
0
        public void TestRetryWithExponentialRetryBackoff()
        {
            var             currentSleep  = 6;
            Func <TimeSpan> retryStrategy = () => {
                var sleep = TimeSpan.FromMilliseconds(currentSleep);
                currentSleep *= 2;
                return(sleep);
            };

            var target = new RetryTarget();

            try
            {
                RetryHelper.Retry(() => target.TargetActionThrows(), retryStrategy, 3);
            }
            catch
            {
                Assert.Equal(3, target.Calls);
                Assert.Equal(24, currentSleep);
            }
        }