diff --git a/src/libraries/System.IO.FileSystem/tests/FileSystemTest.cs b/src/libraries/System.IO.FileSystem/tests/FileSystemTest.cs index 9300660f1418a2..fbc82ffeac6454 100644 --- a/src/libraries/System.IO.FileSystem/tests/FileSystemTest.cs +++ b/src/libraries/System.IO.FileSystem/tests/FileSystemTest.cs @@ -61,7 +61,23 @@ public static string GetNamedPipeServerStreamName() { return @"LOCAL\" + Guid.NewGuid().ToString("N"); } - return Guid.NewGuid().ToString("N"); + + if (PlatformDetection.IsWindows) + { + return Guid.NewGuid().ToString("N"); + } + + const int MinUdsPathLength = 104; // required min is 92, but every platform we currently target is at least 104 + const int MinAvailableForSufficientRandomness = 5; // we want enough randomness in the name to avoid conflicts between concurrent tests + string prefix = Path.Combine(Path.GetTempPath(), "CoreFxPipe_"); + int availableLength = MinUdsPathLength - prefix.Length - 1; // 1 - for possible null terminator + Assert.True(availableLength >= MinAvailableForSufficientRandomness, $"UDS prefix {prefix} length {prefix.Length} is too long"); + + return string.Create(availableLength, 0, (span, _) => + { + for (int i = 0; i < span.Length; i++) + span[i] = (char)('a' + Random.Shared.Next(0, 26)); + }); } ///