public async Task PassthroughIfAllFlushesAreAwaited()
        {
            using (var slabPool = new SlabMemoryPool())
                using (var diagnosticPool = new DiagnosticMemoryPool(slabPool))
                {
                    var pipeWriterFlushTcsArray = new[] {
                        new TaskCompletionSource <FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
                        new TaskCompletionSource <FlushResult>(TaskCreationOptions.RunContinuationsAsynchronously),
                    };

                    var sync                 = new object();
                    var mockPipeWriter       = new MockPipeWriter(pipeWriterFlushTcsArray);
                    var concurrentPipeWriter = new ConcurrentPipeWriter(mockPipeWriter, diagnosticPool, sync);

                    ValueTask <FlushResult> flushTask;

                    lock (sync)
                    {
                        var memory = concurrentPipeWriter.GetMemory();
                        Assert.Equal(1, mockPipeWriter.GetMemoryCallCount);

                        concurrentPipeWriter.Advance(memory.Length);
                        Assert.Equal(1, mockPipeWriter.AdvanceCallCount);

                        flushTask = concurrentPipeWriter.FlushAsync();
                        Assert.Equal(1, mockPipeWriter.FlushCallCount);

                        pipeWriterFlushTcsArray[0].SetResult(default);
예제 #2
0
        public void Advance(int bytes)
        {
            lock (_dataWriterLock)
            {
                ThrowIfSuffixSentOrCompleted();

                if (_streamCompleted)
                {
                    return;
                }

                _startedWritingDataFrames = true;

                _pipeWriter.Advance(bytes);
            }
        }