Esempio n. 1
0
        public async Task ItShouldRetryVoidActionsUpToTheMaximumtryCount()
        {
            int tryCount = 0;

            Func <Task> action = () =>
            {
                ++tryCount;
                throw SqlExceptionMocker.MakeSqlException(
                          FifthweekRetryOnTransientErrorHandler.SqlDeadlockErrorCode);
            };

            Exception exception = null;

            try
            {
                await this.target.HandleAsync(action);
            }
            catch (Exception t)
            {
                exception = t;
            }

            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(RetryLimitExceededException));
            Assert.AreEqual(FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount + 1, tryCount);
            Assert.AreEqual(FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount, this.target.RetryCount);
        }
Esempio n. 2
0
        public async Task ItShouldRetryActionsUntilNonTransientFailure()
        {
            int tryCount = 0;

            Func <Task <int> > action = () =>
            {
                ++tryCount;
                if (tryCount <= FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount)
                {
                    throw SqlExceptionMocker.MakeSqlException(
                              FifthweekRetryOnTransientErrorHandler.SqlDeadlockErrorCode);
                }
                else
                {
                    this.transientErrorDetectionStrategy.Setup(v => v.IsTransient(It.IsAny <Exception>())).Returns(false);
                    throw new DivideByZeroException();
                }
            };

            Exception exception = null;

            try
            {
                await this.target.HandleAsync(action);
            }
            catch (Exception t)
            {
                exception = t;
            }

            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(DivideByZeroException));
            Assert.AreEqual(FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount + 1, tryCount);
            Assert.AreEqual(FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount, this.target.RetryCount);
        }
Esempio n. 3
0
 public async Task ItShouldRetryOnNestedSqlError()
 {
     Assert.IsTrue(this.target.IsTransient(new InvalidOperationException(
                                               "blah",
                                               new DivideByZeroException(
                                                   "blah",
                                                   SqlExceptionMocker.MakeSqlException(
                                                       FifthweekRetryOnTransientErrorHandler.SqlTimeoutErrorCode)))));
 }
Esempio n. 4
0
 public async Task ItShouldRetryOnNestedAggregateSqlError()
 {
     Assert.IsTrue(this.target.IsTransient(new AggregateException(
                                               "blah",
                                               new DivideByZeroException(
                                                   "blah",
                                                   new Exception("Dead end")),
                                               new DivideByZeroException(
                                                   "blah",
                                                   new AggregateException(
                                                       "blah",
                                                       new ExternalErrorException("blah"),
                                                       new Exception(
                                                           "blah",
                                                           SqlExceptionMocker.MakeSqlException(FifthweekRetryOnTransientErrorHandler.SqlTimeoutErrorCode)),
                                                       new EntryPointNotFoundException("blah"))))));
 }
Esempio n. 5
0
        public async Task ItShouldRetryNonVoidActionsUntilSuccess()
        {
            int tryCount = 0;

            Func <Task <int> > action = () =>
            {
                ++tryCount;
                if (tryCount <= FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount)
                {
                    throw SqlExceptionMocker.MakeSqlException(
                              FifthweekRetryOnTransientErrorHandler.SqlDeadlockErrorCode);
                }

                return(Task.FromResult(0));
            };

            await this.target.HandleAsync(action);

            Assert.AreEqual(FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount + 1, tryCount);
            Assert.AreEqual(FifthweekRetryOnTransientErrorHandler.DefaultMaxRetryCount, this.target.RetryCount);
        }
Esempio n. 6
0
 public async Task ItShouldRetryOnSqlAzureTransientError2()
 {
     Assert.IsTrue(this.target.IsTransient(SqlExceptionMocker.MakeSqlException(
                                               40143)));
 }
Esempio n. 7
0
 public async Task ItShouldRetryOnSqlTimeout()
 {
     Assert.IsTrue(this.target.IsTransient(SqlExceptionMocker.MakeSqlException(
                                               FifthweekRetryOnTransientErrorHandler.SqlTimeoutErrorCode)));
 }
Esempio n. 8
0
 public async Task ItShouldNotRetryOnUnsupportedSqlExceptionErrorNumbers()
 {
     Assert.IsFalse(this.target.IsTransient(SqlExceptionMocker.MakeSqlException(0)));
 }