public void When_Deferrals_Disposed() { var deferralManager = new DeferralManager <Deferral>(h => new Deferral(h)); var deferral1 = deferralManager.GetDeferral(); var deferral2 = deferralManager.GetDeferral(); bool isCompleted = false; deferralManager.Completed += (s, e) => { isCompleted = true; }; deferralManager.EventRaiseCompleted(); Assert.IsFalse(isCompleted); deferral1.Dispose(); Assert.IsFalse(isCompleted); deferral2.Dispose(); Assert.IsTrue(isCompleted); }
public async Task When_Completed_Asynchronously_With_Requests() { var deferralManager = new DeferralManager <Deferral>(h => new Deferral(h)); var deferral1 = deferralManager.GetDeferral(); var deferral2 = deferralManager.GetDeferral(); bool lastDeferralCompleting = false; deferralManager.Completed += (s, e) => { Assert.IsTrue(lastDeferralCompleting); Assert.IsFalse(deferralManager.CompletedSynchronously); }; var completedSynchronously = deferralManager.EventRaiseCompleted(); Assert.IsFalse(completedSynchronously); Assert.IsFalse(deferralManager.CompletedSynchronously); await Task.Yield(); deferral2.Complete(); Assert.IsFalse(deferralManager.CompletedSynchronously); await Task.Yield(); Assert.IsFalse(deferralManager.CompletedSynchronously); lastDeferralCompleting = true; deferral1.Complete(); Assert.IsFalse(deferralManager.CompletedSynchronously); }
public void MultipleDeferralsWithOneIncomplete_PreventsCompletion() { AsyncContext.Run(async() => { var dm = new DeferralManager(); var deferral1 = dm.GetDeferral(); var deferral2 = dm.GetDeferral(); var task = dm.SignalAndWaitAsync(); deferral1.Dispose(); await AssertEx.NeverCompletesAsync(task); }); }
public void MultipleDeferralsWithAllCompleted_Completes() { AsyncContext.Run(async() => { var dm = new DeferralManager(); var deferral1 = dm.GetDeferral(); var deferral2 = dm.GetDeferral(); var task = dm.SignalAndWaitAsync(); deferral1.Dispose(); deferral2.Dispose(); await task; }); }
public void TwoDeferralsWithOneCompletedTwice_PreventsCompletion() { Test.Async(async() => { var dm = new DeferralManager(); var deferral1 = dm.GetDeferral(); var deferral2 = dm.GetDeferral(); var task = dm.SignalAndWaitAsync(); deferral1.Dispose(); deferral1.Dispose(); await AssertEx.NeverCompletesAsync(task); }); }
public void When_Completed_Synchronously_With_Requests() { var deferralManager = new DeferralManager <Deferral>(h => new Deferral(h)); var deferral1 = deferralManager.GetDeferral(); var deferral2 = deferralManager.GetDeferral(); deferral2.Complete(); deferral1.Complete(); deferralManager.Completed += (s, e) => { Assert.IsTrue(deferralManager.CompletedSynchronously); }; Assert.IsTrue(deferralManager.EventRaiseCompleted()); Assert.IsTrue(deferralManager.CompletedSynchronously); }
public void When_Many_Deferrals() { var deferralManager = new DeferralManager <Deferral>(h => new Deferral(h)); var random = new Random(42); var deferrals = new List <Deferral>(); for (int i = 0; i < 20; i++) { deferrals.Add(deferralManager.GetDeferral()); } bool isCompleted = false; deferralManager.Completed += (s, e) => { isCompleted = true; }; deferralManager.EventRaiseCompleted(); while (deferrals.Count > 0) { Assert.IsFalse(isCompleted); var randomIndex = random.Next(deferrals.Count); var randomDeferral = deferrals[randomIndex]; randomDeferral.Complete(); deferrals.RemoveAt(randomIndex); } Assert.IsTrue(isCompleted); }
public void IncompleteDeferral_PreventsCompletion() { AsyncContext.Run(async() => { var dm = new DeferralManager(); var deferral = dm.GetDeferral(); await AssertEx.NeverCompletesAsync(dm.SignalAndWaitAsync()); }); }
public SuspendingDeferral GetDeferral() { if (_deferralManager == null) { _deferralManager = new DeferralManager <SuspendingDeferral>(h => new SuspendingDeferral(h)); _deferralManager.Completed += (s, e) => _deferralDone?.Invoke(); } return(_deferralManager.GetDeferral()); }
public Deferral GetDeferral() { if (_deferralManager == null) { _deferralManager = new DeferralManager <Deferral>(h => new Deferral(h)); _deferralManager.Completed += (s, e) => _complete(this); } return(_deferralManager.GetDeferral()); }
public void DeferralCompleted_Completes() { AsyncContext.Run(async() => { var dm = new DeferralManager(); var deferral = dm.GetDeferral(); var task = dm.SignalAndWaitAsync(); Assert.IsFalse(task.IsCompleted); deferral.Dispose(); await task; }); }
public void When_Incomplete_Deferral() { var deferralManager = new DeferralManager <Deferral>(h => new Deferral(h)); var deferral = deferralManager.GetDeferral(); bool testFinished = false; deferralManager.Completed += (s, e) => { if (!testFinished) { Assert.Fail("Should not be called"); } }; var completedSynchronously = deferralManager.EventRaiseCompleted(); // Set to avoid ghost assertion failure (deferral disposal will complete it). testFinished = true; }
public Deferral GetDeferral() => Manager.GetDeferral();
public IDisposable GetDeferral() => _deferralManager.GetDeferral();
public IDisposable GetDeferral() { return(_deferrals.GetDeferral()); }
public IDisposable GetDeferral() { return(_deferralManager.GetDeferral()); }