public void IsDoneIsTrueWhenTaskCompletes() { FutureTask <T> task = new FutureTask <T>(_noOpCall); task.Run(); Assert.IsTrue(task.IsDone); Assert.IsFalse(task.IsCancelled); }
public void CancelFailsOnCompletedTask([Values(true, false)] bool mayInterruptIfRunning) { FutureTask <T> task = new FutureTask <T>(_noOpCall); task.Run(); Assert.IsFalse(task.Cancel(mayInterruptIfRunning)); Assert.IsTrue(task.IsDone); Assert.IsFalse(task.IsCancelled); }
public void CancelSecceedsBeforeRun([Values(true, false)] bool mayInterruptIfRunning) { FutureTask <T> task = new FutureTask <T>(_noOpCall); Assert.IsTrue(task.Cancel(mayInterruptIfRunning)); task.Run(); Assert.IsTrue(task.IsDone); Assert.IsTrue(task.IsCancelled); }
public void TimedGetResultRetrievesValueSetFromAnotherThread() { T result = TestData <T> .One; FutureTask <T> ft = new FutureTask <T>(() => result); Assert.IsFalse(ft.IsDone); Assert.IsFalse(ft.IsCancelled); ThreadManager.StartAndAssertRegistered( "T1", delegate { Assert.That(ft.GetResult(Delays.Medium), Is.EqualTo(result)); }); ft.Run(); ThreadManager.JoinAndVerify(); Assert.IsTrue(ft.IsDone); Assert.IsFalse(ft.IsCancelled); }
public void GetChokesWhenTaskChokes([Values(true, false)] bool isTimed) { FutureTask <T> ft = new FutureTask <T>( delegate { int z = 0; return(TestData <T> .MakeData(5 / z)); }); ft.Run(); Assert.Throws <ExecutionException>( delegate { if (isTimed) { ft.GetResult(Delays.Medium); } else { ft.GetResult(); } }); }