public void WhenOpen_Close() { var gate = new AsyncGate(open: true); gate.Close(); ShouldBeClosed(gate); }
public void WhenOpen_SetClosed() { var gate = new AsyncGate(open: true); gate.IsOpen = false; ShouldBeClosed(gate); }
public void WhenClosed_Open() { var gate = new AsyncGate(); gate.Open(); ShouldBeOpen(gate); }
public void WhenClosed_SetOpen() { var gate = new AsyncGate(); gate.IsOpen = true; ShouldBeOpen(gate); }
public void WhenClosed_Close() { var gate = new AsyncGate(); gate.Close(); ShouldBeClosed(gate); }
public void WhenClosed_SetClosed() { var gate = new AsyncGate(); gate.IsOpen = false; ShouldBeClosed(gate); }
public void WhenOpen_SetOpen() { var gate = new AsyncGate(open: true); gate.IsOpen = true; ShouldBeOpen(gate); }
public void WhenOpen_Open() { var gate = new AsyncGate(open: true); gate.Open(); ShouldBeOpen(gate); }
public void Stampede() { var gate = new AsyncGate(); var herd = Enumerable .Range(0, Environment.ProcessorCount * 32) .Select(_ => Task.Run(async() => { await gate.WaitAsync(); })) .ToList(); gate.Open(); Task.WhenAll(herd); }
public void OnOpeningWhenTasksAreWaiting() { var gate = new AsyncGate(); var sign = 0; var task = Task.Run(async() => { sign = 1; await gate.WaitAsync(); sign = 2; }); WaitUntil(() => sign == 1, 100.Milliseconds()); gate.Open(); WaitUntil(() => sign == 2, 100.Milliseconds()); task.Wait(100.Milliseconds()).Should().BeTrue(); }
public void Construct_Open() { var gate = new AsyncGate(open: true); ShouldBeOpen(gate); }
public void Construct_Closed() { var gate = new AsyncGate(); ShouldBeClosed(gate); }
private static void ShouldBeOpen(AsyncGate gate) { gate.IsOpen.Should().BeTrue(); gate.WaitAsync().Wait(millisecondsTimeout: 100).Should().BeTrue(); }