From 59ad4fc00ae3182fbe195ff6ca41f465f960ffbf Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 29 Jun 2025 00:57:35 -0700 Subject: [PATCH 1/3] Cleanup named mutex tests Deduplicate issues for missing cross-process named mutex support on NativeAOT and Mono Closes #70127 --- .../System.Threading/tests/MutexTests.cs | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Threading/tests/MutexTests.cs b/src/libraries/System.Threading/tests/MutexTests.cs index de4cc8bb7eaf2e..11612984d79b7b 100644 --- a/src/libraries/System.Threading/tests/MutexTests.cs +++ b/src/libraries/System.Threading/tests/MutexTests.cs @@ -13,6 +13,26 @@ namespace System.Threading.Tests { public class MutexTests : FileCleanupTestBase { + private static bool IsCrossProcessNamedMutexSupported + { + get + { + if (PlatformDetection.IsWindows) + return true; + + // Mobile platforms are constrained environments + if (PlatformDetection.IsMobile) + return false; + + // Cross-process named mutex support is not implemented on NativeAOT and Mono + // [ActiveIssue("https://github.com/dotnet/runtime/issues/48720")] + if (PlatformDetection.IsMonoRuntime || PlatformDetection.IsNativeAot) + return false; + + return true; + } + } + [Fact] public void ConstructorAndDisposeTest() { @@ -225,9 +245,7 @@ public void MutualExclusionTest() m.ReleaseMutex(); } - [Fact] - [ActiveIssue("https://github.com/mono/mono/issues/15159", TestRuntimes.Mono)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/70127", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ConditionalFact(nameof(IsCrossProcessNamedMutexSupported))] [PlatformSpecific(TestPlatforms.AnyUnix)] public void Ctor_InvalidNames_Unix() { @@ -344,7 +362,6 @@ public void OpenExisting(string name) } [Fact] - [ActiveIssue("https://github.com/mono/mono/issues/15158", TestRuntimes.Mono)] public void OpenExisting_InvalidNames() { AssertExtensions.Throws("name", () => Mutex.OpenExisting(null, options: default)); @@ -769,8 +786,10 @@ public void AbandonExisting( }); } - [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/36307", TestRuntimes.Mono)] + private static bool IsRemoteExecutorAndCrossProcessNamedMutexSupported => + RemoteExecutor.IsSupported && IsCrossProcessNamedMutexSupported; + + [ConditionalTheory(nameof(IsRemoteExecutorAndCrossProcessNamedMutexSupported))] [MemberData(nameof(NameOptionCombinations_MemberData))] public void CrossProcess_NamedMutex_ProtectedFileAccessAtomic(bool currentUserOnly, bool currentSessionOnly) { @@ -956,7 +975,7 @@ public static TheoryData GetValidNames() { var names = new TheoryData() { Guid.NewGuid().ToString("N") }; - if (PlatformDetection.IsWindows) + if (PlatformDetection.IsWindows || !IsCrossProcessNamedMutexSupported) names.Add(Guid.NewGuid().ToString("N") + new string('a', 1000)); return names; From 6bd5c8e28782abb7bbf29ffa89990bf8caac9fa4 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 29 Jun 2025 23:10:50 -0700 Subject: [PATCH 2/3] Update src/libraries/System.Threading/tests/MutexTests.cs --- src/libraries/System.Threading/tests/MutexTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libraries/System.Threading/tests/MutexTests.cs b/src/libraries/System.Threading/tests/MutexTests.cs index 11612984d79b7b..d97abbad4e0438 100644 --- a/src/libraries/System.Threading/tests/MutexTests.cs +++ b/src/libraries/System.Threading/tests/MutexTests.cs @@ -975,6 +975,9 @@ public static TheoryData GetValidNames() { var names = new TheoryData() { Guid.NewGuid().ToString("N") }; + // Windows native named mutexes and in-proc named mutexes support very long (1000+ char) names. + // Non-Windows cross-process named mutexes are emulated using file system. It imposed limits + // on maximum name length. if (PlatformDetection.IsWindows || !IsCrossProcessNamedMutexSupported) names.Add(Guid.NewGuid().ToString("N") + new string('a', 1000)); From 8f2691bf4bc5d41bae6768963cd46a55869e33e1 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 30 Jun 2025 07:19:12 -0700 Subject: [PATCH 3/3] Update src/libraries/System.Threading/tests/MutexTests.cs --- src/libraries/System.Threading/tests/MutexTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Threading/tests/MutexTests.cs b/src/libraries/System.Threading/tests/MutexTests.cs index d97abbad4e0438..345831191e5066 100644 --- a/src/libraries/System.Threading/tests/MutexTests.cs +++ b/src/libraries/System.Threading/tests/MutexTests.cs @@ -976,7 +976,7 @@ public static TheoryData GetValidNames() var names = new TheoryData() { Guid.NewGuid().ToString("N") }; // Windows native named mutexes and in-proc named mutexes support very long (1000+ char) names. - // Non-Windows cross-process named mutexes are emulated using file system. It imposed limits + // Non-Windows cross-process named mutexes are emulated using file system. It imposes limit // on maximum name length. if (PlatformDetection.IsWindows || !IsCrossProcessNamedMutexSupported) names.Add(Guid.NewGuid().ToString("N") + new string('a', 1000));