Beispiel #1
0
        public void AutoResetBarrierShouldAutoResetUponCompletion()
        {
            var b = new AutoResetAsyncBarrier(2);

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

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

            t3.IsCompleted.Should().BeTrue();
            t4.IsCompleted.Should().BeTrue();
        }
Beispiel #2
0
        public void SettingWaitCountTriggersCancelOnAuto()
        {
            var b  = new AutoResetAsyncBarrier(2);
            var t1 = b.WaitAsync(CancellationToken);

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

            t2.IsCompleted.Should().BeFalse();
            var t3 = b.WaitAsync(CancellationToken);

            t2.IsCompleted.Should().BeTrue();
            t3.IsCompleted.Should().BeTrue();
        }
Beispiel #3
0
        public void AutoResetBarrierShouldAutoResetUponCancellation()
        {
            var b = new AutoResetAsyncBarrier(4);

            using (var cts = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken))
            {
                b.WaitAsync(CancellationToken);
                b.WaitAsync(cts.Token);
                b.WaitAsync(CancellationToken);
                cts.Cancel();
                var tB2 = b.WaitAsync(CancellationToken);
                tB2.IsCompleted.Should().BeFalse();
                var tBrest = new[]
                {
                    b.WaitAsync(CancellationToken),
                    b.WaitAsync(CancellationToken),
                    b.WaitAsync(CancellationToken)
                };
                tB2.IsCompletedSuccessfully.Should().BeTrue();
                tBrest.Should().OnlyContain(t => t.IsCompletedSuccessfully);
            }
        }