Skip to content

Commit

Permalink
Added synchronous test for issue #256
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jan 21, 2025
1 parent 57d758c commit b956051
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/DotNext.Tests/IO/PoolingBufferedStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte> expected = RandomBytes(dataSize);
Expand All @@ -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<byte> 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<byte> 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()
Expand Down

0 comments on commit b956051

Please sign in to comment.