public void OnlyOuterDeadlockRetries() { using (DatabaseContext.GetContext()) { int innerCalls = 0, outerCalls = 0; try { DatabaseContext.RunWithRetry(() => { outerCalls++; DatabaseContext.RunWithRetry(() => { innerCalls++; throw SqlExceptionMocker.MakeSqlException(1205); }); }); Assert.Fail("We should never get here"); } catch (SqlException) { Assert.That(innerCalls, Is.EqualTo(DatabaseContext.DeadlockRetryCount)); Assert.That(outerCalls, Is.EqualTo(DatabaseContext.DeadlockRetryCount)); } } }
public void DeadlockInTransactionDoesntRetry() { using (DatabaseContext.GetContext()) { int calls = 0; try { using (DatabaseContext.GetContext(true)) { DatabaseContext.RunWithRetry(() => { calls++; throw SqlExceptionMocker.MakeSqlException(1205); }); Assert.Fail("We should never get here"); } } catch (SqlException) { Assert.That(calls, Is.EqualTo(1)); } } }
public void OneDeadlock(int code ) { using (DatabaseContext.GetContext()) { bool firstTime = true; try { DatabaseContext.RunWithRetry(() => { if (firstTime) { firstTime = false; throw SqlExceptionMocker.MakeSqlException(code); } }); Assert.That(firstTime, Is.False); } catch (SqlException) { Assert.Fail("We should never get here"); } } }
public void ExceedsRetries() { using (DatabaseContext.GetContext()) { int called = 0; try { DatabaseContext.RunWithRetry(() => { called++; throw SqlExceptionMocker.MakeSqlException(1205); }); Assert.Fail("We should never get here"); } catch (SqlException) { Assert.That(called, Is.EqualTo(DatabaseContext.DeadlockRetryCount)); } } }