Skip to content

Commit 3b71fd8

Browse files
jozkeeadamsitnikdanmoseley
authored
[release/6.0] Don't create multiple large files at the same time (#63032)
* Move NoInt32OverflowInTheBufferingLogic to OuterLoop and address pending feedback (#60606) * Don't create multiple large files at the same time (#62519) * move existing large file tests into a separate type (no code changes) * don't run the large file tests in parallel * use FileOptions.DeleteOnClose to ensure that each test removes it's own file use single large file to test File.ReadAllBytes and ile.ReadAllBytesAsync for both limits * Fix DisableParallelization build issue * Apply suggestions from code review Co-authored-by: Adam Sitnik <[email protected]> * Update src/libraries/System.IO.FileSystem/tests/LargeFileTests.cs Co-authored-by: Adam Sitnik <[email protected]> * Notepad with uppercase (#62487) Co-authored-by: Adam Sitnik <[email protected]> Co-authored-by: Dan Moseley <[email protected]>
1 parent 67b110e commit 3b71fd8

File tree

8 files changed

+110
-81
lines changed

8 files changed

+110
-81
lines changed

src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ private void VerifyNotepadMainWindowTitle(Process process, string filename)
13181318
string expected = Path.GetFileNameWithoutExtension(filename);
13191319

13201320
process.WaitForInputIdle(); // Give the file a chance to load
1321-
Assert.Equal("notepad", process.ProcessName);
1321+
Assert.Equal("notepad", process.ProcessName.ToLower());
13221322

13231323
// Notepad calls CreateWindowEx with pWindowName of empty string, then calls SetWindowTextW
13241324
// with "Untitled - Notepad" then finally if you're opening a file, calls SetWindowTextW

src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,16 @@ public void ProcessStart_UseShellExecute_OnWindows_DoesNotThrow(bool isFolder)
267267
{
268268
if (px != null) // sometimes process is null
269269
{
270-
Assert.Equal("notepad", px.ProcessName);
271-
272-
px.Kill();
273-
Assert.True(px.WaitForExit(WaitInMS));
274-
px.WaitForExit(); // wait for event handlers to complete
270+
try
271+
{
272+
Assert.Equal("notepad", px.ProcessName.ToLower());
273+
}
274+
finally
275+
{
276+
px.Kill();
277+
Assert.True(px.WaitForExit(WaitInMS));
278+
px.WaitForExit(); // wait for event handlers to complete
279+
}
275280
}
276281
}
277282
}

src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytes.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,6 @@ public void ValidWrite(int size)
5757
File.Delete(path);
5858
}
5959

60-
[Fact]
61-
[OuterLoop]
62-
[ActiveIssue("https://github.com/dotnet/runtime/issues/45954", TestPlatforms.Browser)]
63-
public void ReadFileOver2GB()
64-
{
65-
string path = GetTestFilePath();
66-
using (FileStream fs = File.Create(path))
67-
{
68-
fs.SetLength(int.MaxValue + 1L);
69-
}
70-
71-
// File is too large for ReadAllBytes at once
72-
Assert.Throws<IOException>(() => File.ReadAllBytes(path));
73-
}
74-
7560
[Fact]
7661
public void Overwrite()
7762
{

src/libraries/System.IO.FileSystem/tests/File/ReadWriteAllBytesAsync.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Threading.Tasks;
77
using Xunit;
88
using System.IO.Pipes;
9-
using Microsoft.DotNet.XUnitExtensions;
109

1110
namespace System.IO.Tests
1211
{
@@ -70,21 +69,6 @@ public Task AlreadyCanceledAsync()
7069
async () => await File.WriteAllBytesAsync(path, new byte[0], token));
7170
}
7271

73-
[Fact]
74-
[OuterLoop]
75-
[ActiveIssue("https://github.com/dotnet/runtime/issues/45954", TestPlatforms.Browser)]
76-
public Task ReadFileOver2GBAsync()
77-
{
78-
string path = GetTestFilePath();
79-
using (FileStream fs = File.Create(path))
80-
{
81-
fs.SetLength(int.MaxValue + 1L);
82-
}
83-
84-
// File is too large for ReadAllBytes at once
85-
return Assert.ThrowsAsync<IOException>(async () => await File.ReadAllBytesAsync(path));
86-
}
87-
8872
[Fact]
8973
public async Task OverwriteAsync()
9074
{

src/libraries/System.IO.FileSystem/tests/FileStream/Read.cs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,5 @@ public void NegativeReadRootThrows()
1414
Assert.Throws<UnauthorizedAccessException>(() =>
1515
new FileStream(Path.GetPathRoot(Directory.GetCurrentDirectory()), FileMode.Open, FileAccess.Read));
1616
}
17-
18-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))]
19-
[ActiveIssue("https://github.com/dotnet/runtime/issues/45954", TestPlatforms.Browser)]
20-
public void NoInt32OverflowInTheBufferingLogic()
21-
{
22-
const long position1 = 10;
23-
const long position2 = (1L << 32) + position1;
24-
25-
string filePath = GetTestFilePath();
26-
byte[] data1 = new byte[] { 1, 2, 3, 4, 5 };
27-
byte[] data2 = new byte[] { 6, 7, 8, 9, 10 };
28-
byte[] buffer = new byte[5];
29-
30-
using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
31-
{
32-
stream.Seek(position1, SeekOrigin.Begin);
33-
stream.Write(data1, 0, data1.Length);
34-
35-
stream.Seek(position2, SeekOrigin.Begin);
36-
stream.Write(data2, 0, data2.Length);
37-
}
38-
39-
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
40-
{
41-
stream.Seek(position1, SeekOrigin.Begin);
42-
Assert.Equal(buffer.Length, stream.Read(buffer));
43-
Assert.Equal(data1, buffer);
44-
45-
stream.Seek(position2, SeekOrigin.Begin);
46-
Assert.Equal(buffer.Length, stream.Read(buffer));
47-
Assert.Equal(data2, buffer);
48-
}
49-
50-
using (var stream = new BufferedStream(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None, bufferSize: 0)))
51-
{
52-
stream.Seek(position1, SeekOrigin.Begin);
53-
Assert.Equal(buffer.Length, stream.Read(buffer));
54-
Assert.Equal(data1, buffer);
55-
56-
stream.Seek(position2, SeekOrigin.Begin);
57-
Assert.Equal(buffer.Length, stream.Read(buffer));
58-
Assert.Equal(data2, buffer);
59-
}
60-
}
6117
}
6218
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.IO.Tests;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
8+
namespace System.IO.FileSystem.Tests
9+
{
10+
[OuterLoop]
11+
[ActiveIssue("https://github.com/dotnet/runtime/issues/45954", TestPlatforms.Browser)]
12+
[Collection(nameof(NoParallelTests))] // don't create multiple large files at the same time
13+
public class LargeFileTests : FileSystemTest
14+
{
15+
[Fact]
16+
public async Task ReadAllBytesOverLimit()
17+
{
18+
using FileStream fs = new (GetTestFilePath(), FileMode.Create, FileAccess.Write, FileShare.Read, 4096, FileOptions.DeleteOnClose);
19+
20+
foreach (long lengthOverLimit in new long[] { int.MaxValue + 1L })
21+
{
22+
fs.SetLength(lengthOverLimit);
23+
24+
Assert.Throws<IOException>(() => File.ReadAllBytes(fs.Name));
25+
await Assert.ThrowsAsync<IOException>(async () => await File.ReadAllBytesAsync(fs.Name));
26+
}
27+
}
28+
29+
[Fact]
30+
public void NoInt32OverflowInTheBufferingLogic()
31+
{
32+
const long position1 = 10;
33+
const long position2 = (1L << 32) + position1;
34+
35+
string filePath = GetTestFilePath();
36+
byte[] data1 = new byte[] { 1, 2, 3, 4, 5 };
37+
byte[] data2 = new byte[] { 6, 7, 8, 9, 10 };
38+
byte[] buffer = new byte[5];
39+
40+
using (FileStream stream = File.Create(filePath))
41+
{
42+
stream.Seek(position1, SeekOrigin.Begin);
43+
stream.Write(data1);
44+
45+
stream.Seek(position2, SeekOrigin.Begin);
46+
stream.Write(data2);
47+
}
48+
49+
using (FileStream stream = new (filePath, FileMode.Open, FileAccess.Read, FileShare.None, 4096, FileOptions.DeleteOnClose))
50+
{
51+
stream.Seek(position1, SeekOrigin.Begin);
52+
Assert.Equal(buffer.Length, stream.Read(buffer));
53+
Assert.Equal(data1, buffer);
54+
55+
stream.Seek(position2, SeekOrigin.Begin);
56+
Assert.Equal(buffer.Length, stream.Read(buffer));
57+
Assert.Equal(data2, buffer);
58+
}
59+
}
60+
}
61+
62+
[CollectionDefinition(nameof(NoParallelTests), DisableParallelization = true)]
63+
public partial class NoParallelTests { }
64+
}

src/libraries/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Compile Include="Enumeration\ExampleTests.cs" />
5656
<Compile Include="Enumeration\RemovedDirectoryTests.cs" />
5757
<Compile Include="Enumeration\SymbolicLinksTests.cs" />
58+
<Compile Include="LargeFileTests.cs" />
5859
<Compile Include="PathInternalTests.cs" />
5960
<Compile Include="RandomAccess\Base.cs" />
6061
<Compile Include="RandomAccess\GetLength.cs" />

src/libraries/System.IO/tests/BufferedStream/BufferedStreamTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,40 @@ public async Task CopyToTest_ReadBeforeCopy_CopiesAllData(bool copyAsynchronousl
323323
Array.Copy(data, 1, expected, 0, expected.Length);
324324
Assert.Equal(expected, dst.ToArray());
325325
}
326+
327+
[Fact]
328+
[OuterLoop]
329+
[ActiveIssue("https://github.com/dotnet/runtime/issues/45954", TestPlatforms.Browser)]
330+
public void NoInt32OverflowInTheBufferingLogic()
331+
{
332+
const long position1 = 10;
333+
const long position2 = (1L << 32) + position1;
334+
335+
string filePath = Path.GetTempFileName();
336+
byte[] data1 = new byte[] { 1, 2, 3, 4, 5 };
337+
byte[] data2 = new byte[] { 6, 7, 8, 9, 10 };
338+
byte[] buffer = new byte[5];
339+
340+
using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
341+
{
342+
stream.Seek(position1, SeekOrigin.Begin);
343+
stream.Write(data1);
344+
345+
stream.Seek(position2, SeekOrigin.Begin);
346+
stream.Write(data2);
347+
}
348+
349+
using (var stream = new BufferedStream(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None, bufferSize: 0, FileOptions.DeleteOnClose)))
350+
{
351+
stream.Seek(position1, SeekOrigin.Begin);
352+
Assert.Equal(buffer.Length, stream.Read(buffer));
353+
Assert.Equal(data1, buffer);
354+
355+
stream.Seek(position2, SeekOrigin.Begin);
356+
Assert.Equal(buffer.Length, stream.Read(buffer));
357+
Assert.Equal(data2, buffer);
358+
}
359+
}
326360
}
327361

328362
public class BufferedStream_TestLeaveOpen : TestLeaveOpen

0 commit comments

Comments
 (0)