Beispiel #1
0
        public void TestInitialize()
        {
            this.exceptionHandler = new Mock <IExceptionHandler>();
            this.exceptionHandler.Setup(v => v.ReportExceptionAsync(It.IsAny <Exception>()))
            .Callback <Exception>(v => Trace.WriteLine((object)v));

            this.transientErrorDetectionStrategy = new Mock <ITransientErrorDetectionStrategy>();
            this.transientErrorDetectionStrategy.Setup(v => v.IsTransient(It.IsAny <Exception>())).Returns(true);

            this.target = new FifthweekRetryOnTransientErrorHandler(
                this.exceptionHandler.Object,
                this.transientErrorDetectionStrategy.Object);

            this.target.MaxDelay = TimeSpan.FromMilliseconds(10);
        }
Beispiel #2
0
        public async Task ItShouldImmediatelyRetryAfterTheFirstTransientFailure()
        {
            var retryStrategy =
                FifthweekRetryOnTransientErrorHandler.CreateRetryStrategy(
                    FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount,
                    FifthweekRetryOnTransientErrorHandler.DefaultMaxDelay);

            Assert.IsTrue(retryStrategy.FastFirstRetry);

            var      shouldRetry = retryStrategy.GetShouldRetry();
            TimeSpan firstDelay;

            shouldRetry(0, new Exception(), out firstDelay);

            Assert.AreEqual(TimeSpan.Zero, firstDelay);
        }
Beispiel #3
0
        public async Task ItShouldNotPosponeTheUserUnduely()
        {
            var retryStrategy = FifthweekRetryOnTransientErrorHandler.CreateRetryStrategy(
                FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount,
                FifthweekRetryOnTransientErrorHandler.DefaultMaxDelay);

            var shouldRetry = retryStrategy.GetShouldRetry();

            TimeSpan totalDelay = TimeSpan.Zero;

            for (int i = 0; i < FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount; i++)
            {
                TimeSpan newDelay;
                shouldRetry(i, new Exception(), out newDelay);
                Trace.WriteLine(string.Format("Retry {0}, Delay {1}", i, newDelay));
                totalDelay += newDelay;
            }

            Trace.WriteLine(string.Format("Total Delay {0}", totalDelay));

            Assert.IsTrue(totalDelay < TimeSpan.FromSeconds(30));
        }