public async Task PassthroughIfAllFlushesAreAwaited()
        {
            using (var memoryPool = new PinnedBlockMemoryPool())
                using (var diagnosticPool = new DiagnosticMemoryPool(memoryPool))
                {
                    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
    internal MemoryPoolBlock(PinnedBlockMemoryPool pool, int length)
    {
        Pool = pool;

        var pinnedArray = GC.AllocateUninitializedArray <byte>(length, pinned: true);

        Memory = MemoryMarshal.CreateFromPinnedArray(pinnedArray, 0, pinnedArray.Length);
    }