Skip to content

Cleanup named mutex tests #117128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/libraries/System.Threading/tests/MutexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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<ArgumentNullException>("name", () => Mutex.OpenExisting(null, options: default));
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -956,7 +975,10 @@ public static TheoryData<string> GetValidNames()
{
var names = new TheoryData<string>() { Guid.NewGuid().ToString("N") };

if (PlatformDetection.IsWindows)
// 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 imposes limit
// on maximum name length.
if (PlatformDetection.IsWindows || !IsCrossProcessNamedMutexSupported)
names.Add(Guid.NewGuid().ToString("N") + new string('a', 1000));

return names;
Expand Down
Loading