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 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 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 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 GetChokesWhenTimeout() { FutureTask <T> ft = new FutureTask <T>(_noOpCall); Assert.Throws <TimeoutException>(() => ft.GetResult(TimeSpan.FromMilliseconds(1))); }