Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/libraries/System.IO.FileSystem/tests/FileStream/Flush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ public void FlushWriteWithOtherClient(bool? flushToDisk)
using (FileStream fsr = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
fs.Write(TestBuffer, 0, TestBuffer.Length);
Assert.Equal(TestBuffer.Length, fs.Length);

// Make sure that we've actually buffered it, read handle won't see any changes
Assert.Equal(0, fsr.Length);

// previously accessing Length was not causing a Flush of the internal buffer
// after using BufferedStream by FileStream iternally, now it does
// TODO: verify with the reviewers if such change is OK
Assert.Equal(TestBuffer.Length, fs.Length);

// This should cause a write, after it completes the two handles should be in sync
Flush(fs, flushToDisk);
Assert.Equal(TestBuffer.Length, fsr.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ public async Task FlushAsyncWriteWithOtherClient()
using (FileStream fsr = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
fs.Write(TestBuffer, 0, TestBuffer.Length);
Assert.Equal(TestBuffer.Length, fs.Length);

// Make sure that we've actually buffered it, read handle won't see any changes
Assert.Equal(0, fsr.Length);

// previously accessing Length was not causing a Flush of the internal buffer
// after using BufferedStream by FileStream iternally, now it does
// TODO: verify with the reviewers if such change is OK
Assert.Equal(TestBuffer.Length, fs.Length);

// This should cause a write, after it completes the two handles should be in sync
await fs.FlushAsync();
Assert.Equal(TestBuffer.Length, fsr.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ public void DisposeClosesHandle()
}
}

[Fact]
public void DisposingBufferedStreamThatWrapsAFileStreamWhichHasBennClosedViaSafeFileHandleCloseDoesNotThrow()
{
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
{
var bufferedStream = new BufferedStream(fs, 100);

fs.SafeFileHandle.Dispose();

bufferedStream.Dispose(); // must not throw
}
}

[Fact]
public void AccessFlushesFileClosesHandle()
{
Expand Down Expand Up @@ -104,14 +117,7 @@ private async Task ThrowWhenHandlePositionIsChanged(bool useAsync)

fs.WriteByte(0);
fsr.Position++;
if (useAsync && OperatingSystem.IsWindows()) // Async I/O behaviors differ due to kernel-based implementation on Windows
{
Assert.Throws<IOException>(() => FSAssert.CompletesSynchronously(fs.ReadAsync(new byte[1], 0, 1)));
}
else
{
await Assert.ThrowsAsync<IOException>(() => fs.ReadAsync(new byte[1], 0, 1));
}
await Assert.ThrowsAsync<IOException>(() => fs.ReadAsync(new byte[1], 0, 1));

fs.WriteByte(0);
fsr.Position++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public async Task ManyConcurrentWriteAsyncs_OuterLoop(
{
writes[i] = WriteAsync(fs, expectedData, i * writeSize, writeSize, cancellationToken);
Assert.Null(writes[i].Exception);
if (useAsync)
if (useAsync && writes[i].IsCompletedSuccessfully) // TODO: breaking change, verify with reviewers
{
Assert.Equal((i + 1) * writeSize, fs.Position);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\IO\BinaryReader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\BinaryWriter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\BufferedStream.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\BufferedFileStreamStrategy.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\DerivedFileStreamStrategy.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\DirectoryNotFoundException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\EncodingCache.cs" />
Expand Down Expand Up @@ -1623,13 +1624,15 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GlobalizationMode.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HijriCalendar.Win32.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Guid.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\AsyncWindowsFileStreamStrategy.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\DisableMediaInsertionPrompt.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStreamHelpers.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStreamCompletionSource.Win32.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\Path.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PathHelper.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\PathInternal.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\SyncWindowsFileStreamStrategy.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IO\WindowsFileStreamStrategy.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\PasteArguments.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\Loader\LibraryNameVariation.Windows.cs" />
Expand Down
Loading