@@ -13,6 +13,26 @@ namespace System.Threading.Tests
1313{
1414 public class MutexTests : FileCleanupTestBase
1515 {
16+ private static bool IsCrossProcessNamedMutexSupported
17+ {
18+ get
19+ {
20+ if ( PlatformDetection . IsWindows )
21+ return true ;
22+
23+ // Mobile platforms are constrained environments
24+ if ( PlatformDetection . IsMobile )
25+ return false ;
26+
27+ // Cross-process named mutex support is not implemented on NativeAOT and Mono
28+ // [ActiveIssue("https://github.com/dotnet/runtime/issues/48720")]
29+ if ( PlatformDetection . IsMonoRuntime || PlatformDetection . IsNativeAot )
30+ return false ;
31+
32+ return true ;
33+ }
34+ }
35+
1636 [ Fact ]
1737 public void ConstructorAndDisposeTest ( )
1838 {
@@ -225,9 +245,7 @@ public void MutualExclusionTest()
225245 m . ReleaseMutex ( ) ;
226246 }
227247
228- [ Fact ]
229- [ ActiveIssue ( "https://github.com/mono/mono/issues/15159" , TestRuntimes . Mono ) ]
230- [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/70127" , typeof ( PlatformDetection ) , nameof ( PlatformDetection . IsNativeAot ) ) ]
248+ [ ConditionalFact ( nameof ( IsCrossProcessNamedMutexSupported ) ) ]
231249 [ PlatformSpecific ( TestPlatforms . AnyUnix ) ]
232250 public void Ctor_InvalidNames_Unix ( )
233251 {
@@ -344,7 +362,6 @@ public void OpenExisting(string name)
344362 }
345363
346364 [ Fact ]
347- [ ActiveIssue ( "https://github.com/mono/mono/issues/15158" , TestRuntimes . Mono ) ]
348365 public void OpenExisting_InvalidNames ( )
349366 {
350367 AssertExtensions . Throws < ArgumentNullException > ( "name" , ( ) => Mutex . OpenExisting ( null , options : default ) ) ;
@@ -769,8 +786,10 @@ public void AbandonExisting(
769786 } ) ;
770787 }
771788
772- [ ConditionalTheory ( typeof ( RemoteExecutor ) , nameof ( RemoteExecutor . IsSupported ) ) ]
773- [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/36307" , TestRuntimes . Mono ) ]
789+ private static bool IsRemoteExecutorAndCrossProcessNamedMutexSupported =>
790+ RemoteExecutor . IsSupported && IsCrossProcessNamedMutexSupported ;
791+
792+ [ ConditionalTheory ( nameof ( IsRemoteExecutorAndCrossProcessNamedMutexSupported ) ) ]
774793 [ MemberData ( nameof ( NameOptionCombinations_MemberData ) ) ]
775794 public void CrossProcess_NamedMutex_ProtectedFileAccessAtomic ( bool currentUserOnly , bool currentSessionOnly )
776795 {
@@ -956,7 +975,10 @@ public static TheoryData<string> GetValidNames()
956975 {
957976 var names = new TheoryData < string > ( ) { Guid . NewGuid ( ) . ToString ( "N" ) } ;
958977
959- if ( PlatformDetection . IsWindows )
978+ // Windows native named mutexes and in-proc named mutexes support very long (1000+ char) names.
979+ // Non-Windows cross-process named mutexes are emulated using file system. It imposes limit
980+ // on maximum name length.
981+ if ( PlatformDetection . IsWindows || ! IsCrossProcessNamedMutexSupported )
960982 names . Add ( Guid . NewGuid ( ) . ToString ( "N" ) + new string ( 'a' , 1000 ) ) ;
961983
962984 return names ;
0 commit comments