示例#1
0
        public void ShouldNotRetryOnError(string errorCode)
        {
            var mockLogger = new Mock <IDriverLogger>();
            var retryLogic = new ExponentialBackoffRetryLogic(TimeSpan.FromSeconds(30), mockLogger.Object);

            int count = 0;
            var e     = Record.Exception(() => retryLogic.Retry <int>(() =>
            {
                count++;
                throw ParseServerException(errorCode, "an error");
            }));

            e.Should().BeOfType <TransientException>();
            (e as TransientException).Code.Should().Be(errorCode);
            count.Should().Be(1);
            mockLogger.Verify(l => l.Warn(It.IsAny <Exception>(), It.IsAny <string>()), Times.Never);
        }
        public void ShouldNotRetryOnError(string errorCode)
        {
            var mockLogger = new Mock <ILogger>();

            mockLogger.SetupGet(l => l.Level).Returns(LogLevel.Info);
            var retryLogic = new ExponentialBackoffRetryLogic(TimeSpan.FromSeconds(30), mockLogger.Object);
            var timer      = new Stopwatch();

            timer.Start();
            var e = Record.Exception(() => retryLogic.Retry <int>(() =>
            {
                throw ParseServerException(errorCode, "an error");
            }));

            timer.Stop();
            e.Should().BeOfType <TransientException>();
            (e as TransientException).Code.Should().Be(errorCode);
            timer.Elapsed.TotalMilliseconds.Should().BeLessThan(10);
            mockLogger.Verify(l => l.Info(It.IsAny <string>(), It.IsAny <Exception>()), Times.Never);
        }