public void TestFutureCleanupBefore() { object monitor = new object(); for (int i = 0; i < NUM_ITERATIONS; ++i) { bool cleaned = false; int cleanupSum = 0; Action <List <int> > cleanup = intList => { lock (monitor) { cleaned = true; cleanupSum += intList[0]; Monitor.PulseAll(monitor); } }; // Close f before the computation finishes var f = new MyFuture(FunctionSuccess, cleanup); f.Close(); lock (monitor) { while (!cleaned) { Assert.IsTrue(Monitor.Wait(monitor, SLEEP_TIME * 3), "Future not cleaning"); } } Assert.IsTrue(f.IsDone); Assert.AreEqual(3, cleanupSum); } }
public void TestFutureDisposalException() { var f = new MyFuture(FunctionSuccess); f.Close(); Assert.Throws <ObjectDisposedException>(() => { f.TryGetResult(out _); }); }
public void TestFutureCleanupAfter() { for (int i = 0; i < NUM_ITERATIONS; ++i) { int cleanupSum = 0; // Close f after the computation finishes Action <List <int> > cleanup = intList => { cleanupSum += intList[0]; }; var f = new MyFuture(FunctionSuccess, cleanup); Force(f); Assert.IsTrue(f.IsDone); f.Close(); Assert.AreEqual(3, cleanupSum); } }