Example #1
0
        public void ManualResetBarrierShouldResetWhenManuallyReset()
        {
            var b = new ManualResetAsyncBarrier(2);

            b.WaitAsync(CancellationToken);
            b.WaitAsync(CancellationToken);
            var t3 = b.WaitAsync(CancellationToken);

            t3.IsCompleted.Should().BeTrue();
            b.Reset();
            var t4 = b.WaitAsync(CancellationToken);

            t4.IsCompleted.Should().BeFalse();
            var t5 = b.WaitAsync(CancellationToken);

            t4.IsCompleted.Should().BeTrue();
            t5.IsCompleted.Should().BeTrue();
        }
Example #2
0
        public void SettingWaitCountTriggersCancelOnManual()
        {
            var b  = new ManualResetAsyncBarrier(2);
            var t1 = b.WaitAsync(CancellationToken);

            b.WaitCount = 2;
            t1.IsCanceled.Should().BeTrue();
            var t2 = b.WaitAsync(CancellationToken);

            t2.IsCanceled.Should().BeTrue();
            var t3 = b.WaitAsync(CancellationToken);

            t3.IsCanceled.Should().BeTrue();
            b.Reset();
            var t4 = b.WaitAsync(CancellationToken);

            t4.IsCompleted.Should().BeFalse();
            var t5 = b.WaitAsync(CancellationToken);

            t4.IsCompletedSuccessfully.Should().BeTrue();
            t5.IsCompletedSuccessfully.Should().BeTrue();
        }
Example #3
0
        public void ManualResetBarrierShouldNotResetUponCancellation()
        {
            var b = new ManualResetAsyncBarrier(4);

            using (var cts = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken))
            {
                b.WaitAsync(CancellationToken);
                b.WaitAsync(cts.Token);
                b.WaitAsync(CancellationToken);
                cts.Cancel();
                var tA2 = b.WaitAsync(CancellationToken);
                tA2.IsCanceled.Should().BeTrue();
                b.Reset();
                var tB = new[]
                {
                    b.WaitAsync(CancellationToken),
                    b.WaitAsync(CancellationToken),
                    b.WaitAsync(CancellationToken),
                    b.WaitAsync(CancellationToken)
                };
                tB.Should().OnlyContain(t => t.IsCompletedSuccessfully);
            }
        }