IEnumerator TestWhenAllFaultedCoroutine(Fiber [] fibers) { // One fiber will cancel var waitAllFiber = Fiber.WhenAll (fibers); yield return waitAllFiber; // None should be running Assert.IsFalse (fibers.Any (f => f.Status == FiberStatus.Running), "No fibers should have been running"); // All should be complete Assert.IsTrue (fibers.All (f => f.IsCompleted), "All should be complete"); // 2 should be faulted Assert.AreEqual (2, fibers.Count (f => f.IsFaulted), "2 should be faulted"); // None should be canceled Assert.IsFalse (fibers.Any (f => f.IsCanceled), "None should be canceled"); // Result should not be present Assert.IsNull (waitAllFiber.ResultAsObject, "Result should not be present"); // Fiber should be faulted Assert.IsTrue (waitAllFiber.IsFaulted, "Fiber should have been faulted"); // Fiber should have exception Assert.IsNotNull (waitAllFiber.Exception, "Fiber should have exception"); // Exception should have 2 inner exceptions Assert.AreEqual (2, (waitAllFiber.Exception as AggregateException).InnerExceptions.Count, "Fiber should have 2 inner exceptions"); }
IEnumerator TestWhenAnyCoroutine(Fiber[] fibers) { // Wait var waitAllFiber = Fiber.WhenAny(fibers); yield return waitAllFiber; // Verify index 2 was the winner and is done Assert.AreEqual(fibers[2], waitAllFiber.ResultAsObject, "Fiber at index 2 was not the winner and should be"); Assert.IsTrue(fibers[2].IsCompleted, "Fiber at index 2 should have been stopped"); // Others should still be running Assert.IsTrue(fibers.Any(f => f.Status == FiberStatus.Running), "Other fibers should have been running but were not"); // Wait 2s more yield return new YieldForSeconds(2); // Now none should be running Assert.IsTrue(fibers.All(f => f.IsCompleted), "No fibers should have been running"); }
IEnumerator TestWhenAllChildCancellationCoroutine(Fiber [] fibers) { // One fiber will cancel var waitAllFiber = Fiber.WhenAll (fibers); yield return waitAllFiber; // None should be running Assert.IsFalse (fibers.Any (f => f.Status == FiberStatus.Running), "No fibers should have been running"); // All should be complete Assert.IsTrue (fibers.All (f => f.IsCompleted), "All should be complete"); // None should be faulted Assert.IsFalse (fibers.Any (f => f.IsFaulted), "None should be faulted"); // One should be canceled Assert.IsTrue (fibers.Count (f => f.IsCanceled) == 1, "One should be canceled"); // Result should not be present Assert.IsNull (waitAllFiber.ResultAsObject, "Result should not be present"); // Fiber should not be faulted Assert.IsFalse (waitAllFiber.IsFaulted, "Fiber should not be faulted"); // Fiber should be canceled Assert.IsTrue (waitAllFiber.IsCanceled, "Fiber should have been canceled"); }