未验证 提交 4f3fd1a9 编写于 作者: A Adam Sitnik 提交者: GitHub

Fix the buffering bug that blocks SDK (#51151)

* add a failing test that mimcs the SDK bug

* fix the buffering bug
上级 d2e983cd
......@@ -161,6 +161,31 @@ public async Task LengthIsNotCachedAfterHandleHasBeenExposed(FileAccess fileAcce
Assert.Equal(2, stream.Length);
Assert.Equal(2, createdFromHandle.Length);
}
[Fact]
public async Task WriteByteFlushesTheBufferWhenItBecomesFull()
{
string filePath;
List<byte> writtenBytes = new List<byte>();
using (FileStream stream = (FileStream)await CreateWriteOnlyStreamCore(Array.Empty<byte>()))
{
filePath = stream.Name;
stream.WriteByte(0);
writtenBytes.Add(0);
byte[] bytes = new byte[BufferSize - 1];
stream.Write(bytes.AsSpan());
writtenBytes.AddRange(bytes);
stream.WriteByte(1);
writtenBytes.Add(1);
}
byte[] allBytes = File.ReadAllBytes(filePath);
Assert.Equal(writtenBytes.ToArray(), allBytes);
}
}
public class UnbufferedSyncFileStreamStandaloneConformanceTests : FileStreamStandaloneConformanceTests
......
......@@ -602,7 +602,7 @@ private void WriteByteSlow(byte value)
ClearReadBufferBeforeWrite();
EnsureBufferAllocated();
}
else if (_writePos == _bufferSize - 1)
else
{
FlushWrite();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册