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 CancelInterruptsRunningTask() { var t = ThreadManager.GetManagedAction( delegate { Assert.Throws <ThreadInterruptedException>(() => Thread.Sleep(Delays.Medium)); }); FutureTask <T> task = new FutureTask <T>(t, default(T)); new Thread(task.Run).Start(); Thread.Sleep(Delays.Short); Assert.IsTrue(task.Cancel(true)); ThreadManager.JoinAndVerify(); 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 GetChokesWhenInterrupted([Values(true, false)] bool isTimed) { FutureTask <T> ft = new FutureTask <T>(_noOpCall); var t = ThreadManager.StartAndAssertRegistered( "T1", () => Assert.Throws <ThreadInterruptedException>( delegate { if (isTimed) { ft.GetResult(Delays.Medium); } else { ft.GetResult(); } })); Thread.Sleep(Delays.Short); t.Interrupt(); ThreadManager.JoinAndVerify(); }
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(); } }); }
public void GetChokesWhenTaskIsCancelled([Values(true, false)] bool isTimed) { FutureTask <T> ft = new FutureTask <T>( () => Thread.Sleep(Delays.Medium), default(T)); ThreadStart getter = () => Assert.Throws <CancellationException>( delegate { if (isTimed) { ft.GetResult(Delays.Medium); } else { ft.GetResult(); } }); ThreadManager.StartAndAssertRegistered("T", getter, ft.Run); Thread.Sleep(Delays.Short); ft.Cancel(true); ThreadManager.JoinAndVerify(); }
public void CancelDoesNotInterruptRunningTask() { var called = false; FutureTask <T> task = new FutureTask <T>( ThreadManager.GetManagedAction( delegate { Thread.Sleep(Delays.Small); called = true; }), default(T)); ThreadManager.StartAndAssertRegistered(new Thread(task.Run) { Name = "T1" }); Thread.Sleep(Delays.Short); Assert.IsTrue(task.Cancel()); ThreadManager.JoinAndVerify(); Assert.IsTrue(task.IsDone); Assert.IsTrue(task.IsCancelled); Assert.IsTrue(called); }
public void GetChokesWhenTimeout() { FutureTask <T> ft = new FutureTask <T>(_noOpCall); Assert.Throws <TimeoutException>(() => ft.GetResult(TimeSpan.FromMilliseconds(1))); }