Skip to content
Merged
Changes from 2 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 imposed limits
// on maximum name length.
if (PlatformDetection.IsWindows || !IsCrossProcessNamedMutexSupported)
names.Add(Guid.NewGuid().ToString("N") + new string('a', 1000));

return names;
Expand Down
Loading