From b956051941416acba46e71c92c02d1f0319630cb Mon Sep 17 00:00:00 2001 From: sakno Date: Tue, 21 Jan 2025 18:31:39 +0200 Subject: [PATCH] Added synchronous test for issue #256 --- .../IO/PoolingBufferedStreamTests.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/DotNext.Tests/IO/PoolingBufferedStreamTests.cs b/src/DotNext.Tests/IO/PoolingBufferedStreamTests.cs index 1f6ddb6ba..13dfabc7d 100644 --- a/src/DotNext.Tests/IO/PoolingBufferedStreamTests.cs +++ b/src/DotNext.Tests/IO/PoolingBufferedStreamTests.cs @@ -391,7 +391,7 @@ public static void OverwriteStream() } [Fact] - public static async Task RegressionIssue256() + public static async Task RegressionIssue256Async() { const int dataSize = 128 + 3105 + 66 + 3111 + 66 + 3105 + 66 + 2513 + 128; ReadOnlyMemory expected = RandomBytes(dataSize); @@ -413,6 +413,30 @@ public static async Task RegressionIssue256() Equal(expected.Slice(3303, 3107), buffer.Slice(0, 3107)); } } + + [Fact] + public static void RegressionIssue256() + { + const int dataSize = 128 + 3105 + 66 + 3111 + 66 + 3105 + 66 + 2513 + 128; + ReadOnlySpan expected = RandomBytes(dataSize); + using var ms = new MemoryStream(); + + using (var buffered = new PoolingBufferedStream(ms, leaveOpen: true) { MaxBufferSize = 8192 }) + { + buffered.Write(expected); + buffered.Flush(); + } + + ms.Position = 0; + using (var reader = new PoolingBufferedStream(ms, leaveOpen: true) { MaxBufferSize = 4096 }) + { + Span buffer = new byte[dataSize]; + reader.ReadExactly(buffer.Slice(0, 3175)); + reader.Position = 3303; + reader.ReadExactly(buffer.Slice(0, 3107)); + Equal(expected.Slice(3303, 3107), buffer.Slice(0, 3107)); + } + } [Fact] public static void RepeatableReads()