Example #1
0
        public void WhenOpen_Close()
        {
            var gate = new AsyncGate(open: true);

            gate.Close();

            ShouldBeClosed(gate);
        }
Example #2
0
        public void WhenOpen_SetClosed()
        {
            var gate = new AsyncGate(open: true);

            gate.IsOpen = false;

            ShouldBeClosed(gate);
        }
Example #3
0
        public void WhenClosed_Open()
        {
            var gate = new AsyncGate();

            gate.Open();

            ShouldBeOpen(gate);
        }
Example #4
0
        public void WhenClosed_SetOpen()
        {
            var gate = new AsyncGate();

            gate.IsOpen = true;

            ShouldBeOpen(gate);
        }
Example #5
0
        public void WhenClosed_Close()
        {
            var gate = new AsyncGate();

            gate.Close();

            ShouldBeClosed(gate);
        }
Example #6
0
        public void WhenClosed_SetClosed()
        {
            var gate = new AsyncGate();

            gate.IsOpen = false;

            ShouldBeClosed(gate);
        }
Example #7
0
        public void WhenOpen_SetOpen()
        {
            var gate = new AsyncGate(open: true);

            gate.IsOpen = true;

            ShouldBeOpen(gate);
        }
Example #8
0
        public void WhenOpen_Open()
        {
            var gate = new AsyncGate(open: true);

            gate.Open();

            ShouldBeOpen(gate);
        }
Example #9
0
        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);
        }
Example #10
0
        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();
        }
Example #11
0
        public void Construct_Open()
        {
            var gate = new AsyncGate(open: true);

            ShouldBeOpen(gate);
        }
Example #12
0
        public void Construct_Closed()
        {
            var gate = new AsyncGate();

            ShouldBeClosed(gate);
        }
Example #13
0
 private static void ShouldBeOpen(AsyncGate gate)
 {
     gate.IsOpen.Should().BeTrue();
     gate.WaitAsync().Wait(millisecondsTimeout: 100).Should().BeTrue();
 }