Skip to content

Commit 3de6207

Browse files
Remove Net5CompatFileStreamStrategy. (#57735)
1 parent c929be1 commit 3de6207

18 files changed

+6
-2733
lines changed

src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,6 @@ private static Version GetICUVersion()
312312
version & 0xFF);
313313
}
314314

315-
private static readonly Lazy<bool> _net5CompatFileStream = new Lazy<bool>(() => GetStaticNonPublicBooleanPropertyValue("System.IO.Strategies.FileStreamHelpers", "UseNet5CompatStrategy"));
316-
317-
public static bool IsNet5CompatFileStreamEnabled => _net5CompatFileStream.Value;
318-
319-
public static bool IsNet5CompatFileStreamDisabled => !IsNet5CompatFileStreamEnabled;
320-
321315
private static readonly Lazy<bool> s_fileLockingDisabled = new Lazy<bool>(() => GetStaticNonPublicBooleanPropertyValue("Microsoft.Win32.SafeHandles.SafeFileHandle", "DisableFileLocking"));
322316

323317
public static bool IsFileLockingEnabled => IsWindows || !s_fileLockingDisabled.Value;

src/libraries/System.IO.FileSystem/System.IO.FileSystem.sln

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.FileSystem.Disabl
2121
EndProject
2222
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.FileSystem.Manual.Tests", "tests\ManualTests\System.IO.FileSystem.Manual.Tests.csproj", "{534152EB-14A8-4EF4-B181-342A555337F1}"
2323
EndProject
24-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.FileSystem.Net5Compat.Tests", "tests\Net5CompatTests\System.IO.FileSystem.Net5Compat.Tests.csproj", "{48E07F12-8597-40DE-8A37-CCBEB9D54012}"
25-
EndProject
2624
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.FileSystem.Tests", "tests\System.IO.FileSystem.Tests.csproj", "{3A8E16D3-8A22-4076-BB48-2CD1FBFAF81B}"
2725
EndProject
2826
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.CompilerServices.Unsafe", "..\System.Runtime.CompilerServices.Unsafe\ref\System.Runtime.CompilerServices.Unsafe.csproj", "{79A74577-C550-4264-B352-51D304796B89}"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public async Task ReadAsyncCanceledFile(int bufferSize, bool isAsync)
101101
}
102102
}
103103

104-
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported), nameof(PlatformDetection.IsNet5CompatFileStreamDisabled))]
104+
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
105105
[InlineData(FileShare.None, FileOptions.Asynchronous)] // FileShare.None: exclusive access
106106
[InlineData(FileShare.ReadWrite, FileOptions.Asynchronous)] // FileShare.ReadWrite: others can write to the file, the length can't be cached
107107
[InlineData(FileShare.None, FileOptions.None)]

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

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -65,89 +65,5 @@ public void AccessFlushesFileClosesHandle()
6565
Assert.Equal(TestBuffer.Length, fsr.Length);
6666
}
6767
}
68-
69-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNet5CompatFileStreamEnabled))]
70-
public async Task ThrowWhenHandlePositionIsChanged_sync()
71-
{
72-
await ThrowWhenHandlePositionIsChanged(useAsync: false);
73-
}
74-
75-
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported), nameof(PlatformDetection.IsNet5CompatFileStreamEnabled))]
76-
public async Task ThrowWhenHandlePositionIsChanged_async()
77-
{
78-
await ThrowWhenHandlePositionIsChanged(useAsync: true);
79-
}
80-
81-
private async Task ThrowWhenHandlePositionIsChanged(bool useAsync)
82-
{
83-
string fileName = GetTestFilePath();
84-
85-
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, 0x100, useAsync))
86-
{
87-
// write some data to move the position, flush to ensure OS position is updated
88-
fs.Write(TestBuffer, 0, TestBuffer.Length);
89-
fs.Flush();
90-
91-
if (fs.SafeFileHandle.IsInvalid)
92-
{
93-
// nothing to test
94-
return;
95-
}
96-
97-
using (FileStream fsr = new FileStream(fs.SafeFileHandle, FileAccess.Read, TestBuffer.Length, useAsync))
98-
{
99-
Assert.Equal(TestBuffer.Length, fs.Position);
100-
Assert.Equal(TestBuffer.Length, fsr.Position);
101-
102-
// Operations on original filestream will fail if data is in buffer and position changes.
103-
104-
// Put data in FS write buffer and update position from FSR
105-
fs.WriteByte(0);
106-
fsr.Position = 0;
107-
108-
if (useAsync
109-
// Async I/O behaviors differ due to kernel-based implementation on Windows
110-
&& OperatingSystem.IsWindows()
111-
// ReadAsync which in this case (single byte written to buffer) calls FlushAsync is now 100% async
112-
// so it does not complete synchronously anymore
113-
&& PlatformDetection.IsNet5CompatFileStreamEnabled)
114-
{
115-
Assert.Throws<IOException>(() => FSAssert.CompletesSynchronously(fs.ReadAsync(new byte[1], 0, 1)));
116-
}
117-
else
118-
{
119-
await Assert.ThrowsAsync<IOException>(() => fs.ReadAsync(new byte[1], 0, 1));
120-
}
121-
122-
fs.WriteByte(0);
123-
fsr.Position++;
124-
Assert.Throws<IOException>(() => fs.Read(new byte[1], 0, 1));
125-
126-
fs.WriteByte(0);
127-
fsr.Position++;
128-
await Assert.ThrowsAsync<IOException>(() => fs.ReadAsync(new byte[1], 0, 1));
129-
130-
fs.WriteByte(0);
131-
fsr.Position++;
132-
Assert.Throws<IOException>(() => fs.ReadByte());
133-
134-
fs.WriteByte(0);
135-
fsr.Position++;
136-
Assert.Throws<IOException>(() => fs.Seek(0, SeekOrigin.End));
137-
138-
fs.WriteByte(0);
139-
fsr.Position++;
140-
Assert.Throws<IOException>(() => fs.SetLength(2));
141-
142-
fs.WriteByte(0);
143-
fsr.Position++;
144-
Assert.Throws<IOException>(() => fs.Flush());
145-
146-
fs.WriteByte(0);
147-
fsr.Position++;
148-
Assert.Throws<IOException>(() => fs.Dispose());
149-
}
150-
}
151-
}
15268
}
15369
}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,6 @@ public async Task ManyConcurrentWriteAsyncs_OuterLoop(
229229
{
230230
writes[i] = WriteAsync(fs, expectedData, i * writeSize, writeSize, cancellationToken);
231231
Assert.Null(writes[i].Exception);
232-
if (useAsync)
233-
{
234-
// To ensure that the buffer of a FileStream opened for async IO is flushed
235-
// by FlushAsync in asynchronous way, we aquire a lock for every buffered WriteAsync.
236-
// The side effect of this is that the Position of FileStream is not updated until
237-
// the lock is released by a previous operation.
238-
// So now all WriteAsync calls should be awaited before starting another async file operation.
239-
if (PlatformDetection.IsNet5CompatFileStreamEnabled)
240-
{
241-
Assert.Equal((i + 1) * writeSize, fs.Position);
242-
}
243-
}
244232
}
245233

246234
await Task.WhenAll(writes);

src/libraries/System.IO.FileSystem/tests/Net5CompatTests/Net5CompatSwitchTests.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/libraries/System.IO.FileSystem/tests/Net5CompatTests/runtimeconfig.template.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/libraries/System.IO/System.IO.sln

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO", "ref\System.IO.
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO", "src\System.IO.csproj", "{0769544B-1A5D-4D74-94FD-899DF6C39D62}"
99
EndProject
10-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.Net5Compat.Tests", "tests\Net5CompatTests\System.IO.Net5Compat.Tests.csproj", "{0217540D-FA86-41B3-9754-7BB5096ABA3E}"
11-
EndProject
1210
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.IO.Tests", "tests\System.IO.Tests.csproj", "{72923407-7B7B-44A8-BCA6-2DB562835A8F}"
1311
EndProject
1412
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Runtime.CompilerServices.Unsafe", "..\System.Runtime.CompilerServices.Unsafe\ref\System.Runtime.CompilerServices.Unsafe.csproj", "{602525FF-EE47-4938-8979-32DC962109E4}"

src/libraries/System.IO/tests/Net5CompatTests/System.IO.Net5Compat.Tests.csproj

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)