public void Failed_tasks_sleeps_and_retries() {
     var handler = new DispatchHandler();
     var dispatcher = new UpdateRecordDispatcher(handler.Dispatch, 1, 1, 2.Seconds());
     var firstAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(5.Seconds()));
     var secondAttempt = handler.AddCallback((d, r) => { }, new Result<UpdateRecord>(5.Seconds()));
     dispatcher.Dispatch(new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"), new Result());
     Assert.IsFalse(firstAttempt.Block().HasException, "first attempt wasn't called");
     var stopwatch = Stopwatch.StartNew();
     Assert.IsFalse(secondAttempt.Block().HasException, "second attempt wasn't called");
     stopwatch.Stop();
     Assert.GreaterOrEqual(stopwatch.Elapsed, 2.Seconds(), string.Format("expected at least 2 second delay, took {0:0.00}s", stopwatch.Elapsed.TotalSeconds));
 }
 public void Dispatcher_retries_specified_times() {
     var handler = new DispatchHandler();
     var dispatcher = new UpdateRecordDispatcher(handler.Dispatch, 1, 2, 0.Seconds());
     var firstAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(2.Seconds()));
     var secondAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(2.Seconds()));
     var thirddAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(2.Seconds()));
     var fourthAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(5.Seconds()));
     dispatcher.Dispatch(new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default"), new Result());
     Assert.IsFalse(firstAttempt.Block().HasException, "first attempt wasn't called");
     Assert.IsFalse(secondAttempt.Block().HasException, "second attempt wasn't called");
     Assert.IsFalse(thirddAttempt.Block().HasException, "third attempt wasn't called");
     Assert.IsTrue(fourthAttempt.Block().HasException, "fourth attempt shouldn't have happened");
 }
 public void Failed_task_sleep_does_not_block_next_task() {
     var handler = new DispatchHandler();
     var dispatcher = new UpdateRecordDispatcher(handler.Dispatch, 1, 1, 2.Seconds());
     var r1 = new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default");
     var r2 = new UpdateRecord(new XUri("mock://foo"), new XDoc("meta"), "default");
     var r1firstAttempt = handler.AddCallback((d, r) => r.Throw(new Exception()), new Result<UpdateRecord>(1.Seconds()));
     var r2firstAttempt = handler.AddCallback((d, r) => { }, new Result<UpdateRecord>(1.Seconds()));
     var r1SecondAttempt = handler.AddCallback((d, r) => { }, new Result<UpdateRecord>(5.Seconds()));
     dispatcher.Dispatch(r1, new Result());
     dispatcher.Dispatch(r2, new Result());
     Assert.IsFalse(r1firstAttempt.Block().HasException, "r1 first attempt wasn't called");
     Assert.IsFalse(r1firstAttempt.Block().HasException, "r2 first attempt wasn't called");
     Assert.IsFalse(r1SecondAttempt.Block().HasException, "r2 second attempt wasn't called");
 }