From 1a6577d197343e78451969dcb586baeff39bec1e Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 12 Apr 2019 11:55:20 -0700 Subject: [PATCH] This should fix the flaky test (dotnet/corefx#36826) - The pool in the test wasn't being used (This was changed in a previous commit) - Use the DisposeTrackingBufferPool to make sure we allocated the number of segments we expect Commit migrated from https://github.com/dotnet/corefx/commit/6eeed98a406adf281649e94546975d52c72465e6 --- .../tests/PipeReaderCopyToAsyncTests.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.IO.Pipelines/tests/PipeReaderCopyToAsyncTests.cs b/src/libraries/System.IO.Pipelines/tests/PipeReaderCopyToAsyncTests.cs index 4ebb627..a0284d1 100644 --- a/src/libraries/System.IO.Pipelines/tests/PipeReaderCopyToAsyncTests.cs +++ b/src/libraries/System.IO.Pipelines/tests/PipeReaderCopyToAsyncTests.cs @@ -69,15 +69,17 @@ namespace System.IO.Pipelines.Tests [Fact] public async Task MultiSegmentWritesUntilFailure() { - using (var pool = new TestMemoryPool()) + using (var pool = new DisposeTrackingBufferPool()) { - var pipe = new Pipe(s_testOptions); - pipe.Writer.WriteEmpty(pool.MaxBufferSize); - pipe.Writer.WriteEmpty(pool.MaxBufferSize); - pipe.Writer.WriteEmpty(pool.MaxBufferSize); + var pipe = new Pipe(new PipeOptions(pool, readerScheduler: PipeScheduler.Inline, useSynchronizationContext: false)); + pipe.Writer.WriteEmpty(4096); + pipe.Writer.WriteEmpty(4096); + pipe.Writer.WriteEmpty(4096); await pipe.Writer.FlushAsync(); pipe.Writer.Complete(); + Assert.Equal(3, pool.CurrentlyRentedBlocks); + var stream = new ThrowAfterNWritesStream(2); try { @@ -91,9 +93,15 @@ namespace System.IO.Pipelines.Tests Assert.Equal(2, stream.Writes); + Assert.Equal(1, pool.CurrentlyRentedBlocks); + Assert.Equal(2, pool.DisposedBlocks); + ReadResult result = await pipe.Reader.ReadAsync(); Assert.Equal(4096, result.Buffer.Length); pipe.Reader.Complete(); + + Assert.Equal(0, pool.CurrentlyRentedBlocks); + Assert.Equal(3, pool.DisposedBlocks); } } -- 2.7.4