public static async Task CorrectGarbageCollection() { for (int j = 0; j < 10; j++) { Task t1, t2; using var barrier = new AsyncBarrier(3); t1 = barrier.SignalAndWaitAsync(); t2 = barrier.SignalAndWaitAsync(); await barrier.SignalAndWaitAsync(); GC.Collect(); await Task.WhenAll(t1, t2); } }
public static async Task RemovingWaitingParticipants() { using var barrier = new AsyncBarrier(4); var task = barrier.SignalAndWaitAsync(); while (barrier.ParticipantsRemaining > 3) { await Task.Delay(100); } barrier.RemoveParticipants(2); Equal(1, barrier.ParticipantsRemaining); Throws <ArgumentOutOfRangeException>(() => barrier.RemoveParticipants(20)); Equal(1, barrier.ParticipantsRemaining); barrier.RemoveParticipant(); Equal(0, barrier.ParticipantsRemaining); }
public static async Task PhaseCompletion() { using var barrier = new AsyncBarrier(3); ICollection <Task> tasks = new LinkedList <Task>(); Equal(0, barrier.CurrentPhaseNumber); tasks.Add(barrier.SignalAndWaitAsync()); tasks.Add(barrier.SignalAndWaitAsync()); tasks.Add(barrier.SignalAndWaitAsync()); await Task.WhenAll(tasks); Equal(1, barrier.CurrentPhaseNumber); tasks.Clear(); tasks.Add(barrier.SignalAndWaitAsync()); tasks.Add(barrier.SignalAndWaitAsync()); tasks.Add(barrier.SignalAndWaitAsync()); await Task.WhenAll(tasks); Equal(2, barrier.CurrentPhaseNumber); }