예제 #1
0
        public void CancellationCancelsReadTasks()
        {
            var sut   = new BufferedChannel <int>(0);
            var task1 = sut.TryReadSafeAsync();
            var task2 = sut.TryReadSafeAsync();

            sut.Terminate();
            task1.Result.HasValue.ShouldBeFalse();
            task2.Result.HasValue.ShouldBeFalse();
        }
예제 #2
0
        public void FailCancelsReadTasks()
        {
            var sut   = new BufferedChannel <int>(0);
            var task1 = sut.TryReadSafeAsync();
            var task2 = sut.TryReadSafeAsync();

            sut.Terminate(new InvalidOperationException());
            task1.Result.HasValue.ShouldBeFalse();
            task2.Result.HasValue.ShouldBeFalse();
        }
예제 #3
0
        public void ResetCancelsReadTasks()
        {
            var sut       = new BufferedChannel <int>(0);
            var readTask1 = sut.TryReadSafeAsync();
            var readTask2 = sut.TryReadSafeAsync();

            sut.Reset();
            readTask1.Result.HasValue.ShouldBeFalse();
            readTask2.Result.HasValue.ShouldBeFalse();
        }
예제 #4
0
        public void FailCompletesChannelEvenIfBufferIsNotEmpty()
        {
            var sut = new BufferedChannel <int>(2);

            sut.TryWriteSafe(1);
            sut.TryWriteSafe(2);
            sut.Terminate(new InvalidOperationException());
            sut.Completion.IsCompleted.ShouldBe(false);
            sut.TryReadSafe(out int _).ShouldBe(true);
            sut.TryReadSafe(out int _).ShouldBe(true);
            var result = Should.CompleteIn(() => sut.TryReadSafeAsync().AsTask(), TimeSpan.FromSeconds(1));

            result.HasValue.ShouldBeFalse();
            sut.Completion.IsFaulted.ShouldBeTrue();
        }
예제 #5
0
        public void CancellationCompletesChannel()
        {
            var sut = new BufferedChannel <int>(2);

            sut.TryWriteSafe(1);
            sut.TryWriteSafe(2);
            sut.Terminate();
            sut.Completion.IsCompleted.ShouldBe(false);
            sut.TryReadSafe(out int _).ShouldBe(true);
            sut.TryReadSafe(out int _).ShouldBe(true);
            var result = sut.TryReadSafeAsync().ShouldCompleteIn(Timeout1Sec);

            result.HasValue.ShouldBeFalse();
            sut.Completion.IsCanceled.ShouldBeTrue();
        }