Skip to content

Commit

Permalink
big file (#92682)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmoseley authored Oct 17, 2023
1 parent 3086d8a commit c657cb0
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/libraries/System.IO.FileSystem/tests/FileStream/ctor_options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void PreallocationSize(FileAccess access, FileMode mode)
}
}

[OuterLoop("Might allocate 1 TB file if there is enough space on the disk")]
[ActiveIssue("https://github.com/dotnet/runtime/issues/92624", TestPlatforms.Windows)]
// macOS fcntl doc does not mention ENOSPC error: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fcntl.2.html
// But depending on the OS version, it might actually return it.
// Since we don't want to have unstable tests, it's better to not run it on macOS at all.
Expand All @@ -162,21 +162,23 @@ public void PreallocationSize(FileAccess access, FileMode mode)
[InlineData(FileMode.CreateNew)]
public void WhenDiskIsFullTheErrorMessageContainsAllDetails(FileMode mode)
{
const long tooMuch = 1024L * 1024L * 1024L * 1024L; // 1 TB

const long tooMuch = 1024L * 1024L * 1024L * 1024L * 1024L * 1024L; // 1 Exbibyte .. we are assuming this is not available
string filePath = GetTestFilePath();

IOException ex = Assert.Throws<IOException>(() => CreateFileStream(filePath, mode, FileAccess.Write, FileShare.None, bufferSize: 1, FileOptions.None, tooMuch));
Assert.Contains(filePath, ex.Message);
Assert.Contains(tooMuch.ToString(), ex.Message);

// ensure it was NOT created
bool exists = File.Exists(filePath);
if (exists)
try
{
File.Delete(filePath);
// not using Assert.Throws because in the event of failure, we want to dispose, so the next test isn't affected
using FileStream fs = CreateFileStream(filePath, mode, FileAccess.Write, FileShare.None, bufferSize: 1, FileOptions.None, tooMuch);
Assert.Fail($"Expected to throw IOException, {fs.Length}");
}
catch (IOException ex)
{
Assert.Contains(filePath, ex.Message);
Assert.Contains(tooMuch.ToString(), ex.Message);

// ensure it was NOT created
Assert.False(File.Exists(filePath));
}
Assert.False(exists);
}
}
}

0 comments on commit c657cb0

Please sign in to comment.