22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5+ using System . Collections . Generic ;
6+ using System . Threading . Tasks ;
57using Xunit ;
68
79namespace System . IO . Pipes . Tests
@@ -38,5 +40,49 @@ public static void CreateServer_ConnectClient()
3840 }
3941 }
4042 }
43+
44+ [ Fact ]
45+ public static void CreateMultipleServers_ConnectMultipleClients ( )
46+ {
47+ var name1 = GetUniquePipeName ( ) ;
48+ var name2 = GetUniquePipeName ( ) ;
49+ var name3 = GetUniquePipeName ( ) ;
50+ using ( var server1 = new NamedPipeServerStream ( name1 , PipeDirection . InOut , 1 , PipeTransmissionMode . Byte , PipeOptions . CurrentUserOnly ) )
51+ using ( var server2 = new NamedPipeServerStream ( name2 , PipeDirection . InOut , 1 , PipeTransmissionMode . Byte , PipeOptions . CurrentUserOnly ) )
52+ using ( var server3 = new NamedPipeServerStream ( name3 , PipeDirection . InOut , 1 , PipeTransmissionMode . Byte , PipeOptions . CurrentUserOnly ) )
53+ {
54+ using ( var client1 = new NamedPipeClientStream ( "." , name1 , PipeDirection . InOut , PipeOptions . CurrentUserOnly ) )
55+ using ( var client2 = new NamedPipeClientStream ( "." , name2 , PipeDirection . InOut , PipeOptions . CurrentUserOnly ) )
56+ using ( var client3 = new NamedPipeClientStream ( "." , name3 , PipeDirection . InOut , PipeOptions . CurrentUserOnly ) )
57+ {
58+ client1 . Connect ( ) ;
59+ client2 . Connect ( ) ;
60+ client3 . Connect ( ) ;
61+ }
62+ }
63+ }
64+
65+ [ Fact ]
66+ public static void CreateMultipleServers_ConnectMultipleClients_MultipleThreads ( )
67+ {
68+ List < Task > tasks = new List < Task > ( ) ;
69+ for ( int i = 0 ; i < 3 ; i ++ )
70+ {
71+ tasks . Add ( Task . Run ( ( ) =>
72+ {
73+ var name = GetUniquePipeName ( ) ;
74+ using ( var server = new NamedPipeServerStream ( name , PipeDirection . InOut , 1 , PipeTransmissionMode . Byte , PipeOptions . CurrentUserOnly ) )
75+ {
76+ using ( var client = new NamedPipeClientStream ( "." , name , PipeDirection . InOut , PipeOptions . CurrentUserOnly ) )
77+ {
78+ // Should not fail to connect since both, the server and client have the same owner.
79+ client . Connect ( ) ;
80+ }
81+ }
82+ } ) ) ;
83+ }
84+
85+ Task . WaitAll ( tasks . ToArray ( ) ) ;
86+ }
4187 }
4288}
0 commit comments