Skip to content

Commit a2d316b

Browse files
authored
Fix some randomly failing Perf.File tests on wasm/aot (#2601)
On wasm/aot, `System.IO.FileSystem/Perf.File`'s `CopyTo`, `CopyToOverride`, and `ReadAllBytes` benchmarks fail randomly with: ``` ---> System.IO.IOException: The file '/tmp/' already exists. at BenchmarkDotNet.Autogenerated.Runnable_48.Run(IHost host, String benchmarkName) at System.Reflection.MethodInvoker.InterpretedInvoke(Object , Span`1 , BindingFlags ) --- End of inner exception stack trace --- at BenchmarkDotNet.Autogenerated.UniqueProgramName.AfterAssemblyLoadingAttached(String[] args) ``` .. due to `Path.GetTempFileName()` being buggy - dotnet/runtime#73721. In `SetupReadAllBytes`, we are building the test file path as: ```csharp _testFilePath = Path.Combine(baseDir, Path.GetTempFileName()) ``` .. but the `Path.GetTempFileName()` is not appropriate here, as it will return a full path, and it will create the file. Instead we can use `Path.GetRandomFileName()` which should avoid the underlying issue completely. Fixes dotnet/runtime#74104 .
1 parent b0a1daf commit a2d316b

File tree

1 file changed

+2
-2
lines changed
  • src/benchmarks/micro/libraries/System.IO.FileSystem

1 file changed

+2
-2
lines changed

src/benchmarks/micro/libraries/System.IO.FileSystem/Perf.File.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void SetupReadAllBytes()
9494
{
9595
// use non-temp file path to ensure that we don't test some unusal File System on Unix
9696
string baseDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
97-
File.WriteAllBytes(_testFilePath = Path.Combine(baseDir, Path.GetTempFileName()), Array.Empty<byte>());
97+
File.WriteAllBytes(_testFilePath = Path.Combine(baseDir, Path.GetRandomFileName()), Array.Empty<byte>());
9898
_filesToRead = new Dictionary<int, string>()
9999
{
100100
{ HalfKibibyte, WriteBytes(HalfKibibyte) },
@@ -106,7 +106,7 @@ public void SetupReadAllBytes()
106106

107107
string WriteBytes(int fileSize)
108108
{
109-
string filePath = Path.Combine(baseDir, Path.GetTempFileName());
109+
string filePath = Path.Combine(baseDir, Path.GetRandomFileName());
110110
File.WriteAllBytes(filePath, ValuesGenerator.Array<byte>(fileSize));
111111
return filePath;
112112
}

0 commit comments

Comments
 (0)