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);
Esempio n. 2
0
        public Memory<byte> GetMemory(int sizeHint = 0)
        {
            lock (_dataWriterLock)
            {
                ThrowIfSuffixSentOrCompleted();

                if (_streamCompleted)
                {
                    return GetFakeMemory(sizeHint);
                }

                return _pipeWriter.GetMemory(sizeHint);
            }
        }