public void TestSuccessfulProcedure() { var proc = new UnreliableProcedure(0); int failedAttempts; Procedure.Retry(() => proc.DoWork(), out failedAttempts, attempts: 5); Assert.AreEqual(0, failedAttempts); }
public void TestSuccessfulAsyncProcedure() { var proc = new UnreliableProcedure(3); Assert.DoesNotThrow(async() => { await Procedure.RetryAsync(proc.DoWork, attempts: 5); }); }
public void TestFailedAsyncProcedure() { var proc = new UnreliableProcedure(10); Assert.Throws(typeof(Exception), async() => { await Procedure.RetryAsync(proc.DoWork, attempts: 5); }); }
public void TestSuccessfulProcedureWithReturn() { var proc = new UnreliableProcedure(0); string returned; int failedAttempts; returned = Procedure.Retry <string>(() => proc.DoWorkAndReturn(), out failedAttempts, attempts: 5); Assert.AreEqual(0, failedAttempts); Assert.AreEqual("success", returned); }
public void TestSuccessAfterFailure() { var proc = new UnreliableProcedure(3); int failedAttempts = -1; Assert.DoesNotThrow(() => { Procedure.Retry(() => proc.DoWork(), out failedAttempts, attempts: 5); }); Assert.AreEqual(3, failedAttempts); }
public void TestFailedProcedure() { var proc = new UnreliableProcedure(10); int failedAttempts = -1; Assert.Throws(typeof(Exception), () => { Procedure.Retry(() => proc.DoWork(), out failedAttempts, attempts: 5); }); Assert.AreEqual(5, failedAttempts); }
public void TestSuccessAfterFailureWithReturn() { var proc = new UnreliableProcedure(3); int failedAttempts = -1; string returned = null; Assert.DoesNotThrow(() => { returned = Procedure.Retry <string>(() => proc.DoWorkAndReturn(), out failedAttempts, attempts: 5); }); Assert.AreEqual(3, failedAttempts); Assert.AreEqual("success", returned); }
public void TestFailedProcedureWithReturn() { var proc = new UnreliableProcedure(10); int failedAttempts = -1; string returned = null; Assert.Throws(typeof(Exception), () => { returned = Procedure.Retry <string>(() => proc.DoWorkAndReturn(), out failedAttempts, attempts: 5); }); Assert.AreEqual(5, failedAttempts); Assert.IsNull(returned); }
public void TestSuccessfulAsyncProcedureWithReturn() { var proc = new UnreliableProcedure(0); string returned = null; Assert.DoesNotThrow(() => { returned = Task.Run <string>(async() => { return(await Procedure.RetryAsync <string>(() => proc.DoWorkAndReturn(), attempts: 5)); }).Result; }); Assert.AreEqual("success", returned); }
public void TestFailedProcedureWithTimeInBetween() { var proc = new UnreliableProcedure(10); int failedAttempts = -1; int milliSecondsToWait = 50; var startTime = DateTime.Now; Assert.Throws(typeof(Exception), () => { Procedure.Retry(() => proc.DoWork(), out failedAttempts, attempts: 5, wait: new TimeSpan(0, 0, 0, 0, milliSecondsToWait)); }); var endTime = DateTime.Now; var elapsedTime = endTime - startTime; Assert.GreaterOrEqual(elapsedTime.Milliseconds, milliSecondsToWait * (failedAttempts - 1)); }
public void TestFailedAsyncProcedureWithReturn() { var proc = new UnreliableProcedure(10); string returned = null; var exception = Assert.Throws <AggregateException>(() => { returned = Task.Run <string>(async() => { return(await Procedure.RetryAsync <string>(() => proc.DoWorkAndReturn(), attempts: 5)); }).Result; }); Assert.AreEqual("Procedure failed", exception.InnerException.Message); Assert.IsNull(returned); }