@@ -63,7 +63,16 @@ public abstract class NamedPipeStreamConformanceTests : PipeStreamConformanceTes
63
63
{
64
64
protected override bool BrokenPipePropagatedImmediately => OperatingSystem . IsWindows ( ) ; // On Unix, implemented on Sockets, where it won't propagate immediate
65
65
66
- protected abstract ( NamedPipeServerStream Server , NamedPipeClientStream Client ) CreateServerAndClientStreams ( ) ;
66
+ protected abstract NamedPipeServerStream CreateServerStream ( string pipeName , int maxInstances = 1 ) ;
67
+ protected abstract NamedPipeClientStream CreateClientStream ( string pipeName ) ;
68
+
69
+ protected ( NamedPipeServerStream Server , NamedPipeClientStream Client ) CreateServerAndClientStreams ( )
70
+ {
71
+ string pipeName = GetUniquePipeName ( ) ;
72
+ NamedPipeServerStream server = CreateServerStream ( pipeName ) ;
73
+ NamedPipeClientStream client = CreateClientStream ( pipeName ) ;
74
+ return ( server , client ) ;
75
+ }
67
76
68
77
protected sealed override async Task < StreamPair > CreateConnectedStreamsAsync ( )
69
78
{
@@ -88,6 +97,15 @@ protected sealed override async Task<StreamPair> CreateConnectedStreamsAsync()
88
97
return ( ( NamedPipeServerStream ) streams . Stream2 , ( NamedPipeClientStream ) streams . Stream1 ) ;
89
98
}
90
99
100
+ protected async Task ValidateDisposedExceptionsAsync ( NamedPipeServerStream server )
101
+ {
102
+ Assert . Throws < ObjectDisposedException > ( ( ) => server . Disconnect ( ) ) ;
103
+ Assert . Throws < ObjectDisposedException > ( ( ) => server . GetImpersonationUserName ( ) ) ;
104
+ Assert . Throws < ObjectDisposedException > ( ( ) => server . WaitForConnection ( ) ) ;
105
+ await Assert . ThrowsAsync < ObjectDisposedException > ( ( ) => server . WaitForConnectionAsync ( ) ) ;
106
+ await ValidateDisposedExceptionsAsync ( server as Stream ) ;
107
+ }
108
+
91
109
/// <summary>
92
110
/// Yields every combination of testing options for the OneWayReadWrites test
93
111
/// </summary>
@@ -629,6 +647,37 @@ public async Task CancelTokenOn_Client_ReadWriteCancelledToken_Throws_OperationC
629
647
await Assert . ThrowsAnyAsync < OperationCanceledException > ( ( ) => clientWriteToken ) ;
630
648
}
631
649
}
650
+
651
+ [ Fact ]
652
+ public async Task TwoServerInstances_OnceDisposed_Throws ( )
653
+ {
654
+ string pipeName = GetUniquePipeName ( ) ;
655
+ NamedPipeServerStream server1 = CreateServerStream ( pipeName , 2 ) ;
656
+ using NamedPipeServerStream server2 = CreateServerStream ( pipeName , 2 ) ;
657
+
658
+ Task wait1 = server1 . WaitForConnectionAsync ( ) ;
659
+ Task wait2 = server2 . WaitForConnectionAsync ( ) ;
660
+ server1 . Dispose ( ) ;
661
+ await ValidateDisposedExceptionsAsync ( server1 ) ;
662
+
663
+ using NamedPipeClientStream client = CreateClientStream ( pipeName ) ;
664
+ await client . ConnectAsync ( ) ;
665
+
666
+ await Assert . ThrowsAsync < IOException > ( ( ) => wait1 ) ;
667
+
668
+ await wait2 ;
669
+
670
+ foreach ( ( Stream writeable , Stream readable ) in GetReadWritePairs ( ( server2 , client ) ) )
671
+ {
672
+ byte [ ] sent = new byte [ ] { 123 } ;
673
+ byte [ ] received = new byte [ ] { 0 } ;
674
+
675
+ Task t = Task . Run ( ( ) => writeable . Write ( sent , 0 , sent . Length ) ) ;
676
+ Assert . Equal ( sent . Length , readable . Read ( received , 0 , sent . Length ) ) ;
677
+ Assert . Equal ( sent , received ) ;
678
+ await t ;
679
+ }
680
+ }
632
681
}
633
682
634
683
public sealed class AnonymousPipeTest_ServerIn_ClientOut : AnonymousPipeStreamConformanceTests
@@ -653,34 +702,28 @@ protected override (AnonymousPipeServerStream Server, AnonymousPipeClientStream
653
702
654
703
public sealed class NamedPipeTest_ServerOut_ClientIn : NamedPipeStreamConformanceTests
655
704
{
656
- protected override ( NamedPipeServerStream Server , NamedPipeClientStream Client ) CreateServerAndClientStreams ( )
657
- {
658
- string pipeName = PipeStreamConformanceTests . GetUniquePipeName ( ) ;
659
- var server = new NamedPipeServerStream ( pipeName , PipeDirection . Out , 1 , PipeTransmissionMode . Byte , PipeOptions . Asynchronous ) ;
660
- var client = new NamedPipeClientStream ( "." , pipeName , PipeDirection . In , PipeOptions . Asynchronous ) ;
661
- return ( server , client ) ;
662
- }
705
+ protected override NamedPipeServerStream CreateServerStream ( string pipeName , int maxInstances = 1 ) =>
706
+ new NamedPipeServerStream ( pipeName , PipeDirection . Out , maxInstances , PipeTransmissionMode . Byte , PipeOptions . Asynchronous ) ;
707
+
708
+ protected override NamedPipeClientStream CreateClientStream ( string pipeName ) =>
709
+ new NamedPipeClientStream ( "." , pipeName , PipeDirection . In , PipeOptions . Asynchronous ) ;
663
710
}
664
711
665
712
public sealed class NamedPipeTest_ServerIn_ClientOut : NamedPipeStreamConformanceTests
666
713
{
667
- protected override ( NamedPipeServerStream Server , NamedPipeClientStream Client ) CreateServerAndClientStreams ( )
668
- {
669
- string pipeName = PipeStreamConformanceTests . GetUniquePipeName ( ) ;
670
- var server = new NamedPipeServerStream ( pipeName , PipeDirection . In , 1 , PipeTransmissionMode . Byte , PipeOptions . Asynchronous ) ;
671
- var client = new NamedPipeClientStream ( "." , pipeName , PipeDirection . Out , PipeOptions . Asynchronous ) ;
672
- return ( server , client ) ;
673
- }
714
+ protected override NamedPipeServerStream CreateServerStream ( string pipeName , int maxInstances = 1 ) =>
715
+ new NamedPipeServerStream ( pipeName , PipeDirection . In , maxInstances , PipeTransmissionMode . Byte , PipeOptions . Asynchronous ) ;
716
+
717
+ protected override NamedPipeClientStream CreateClientStream ( string pipeName ) =>
718
+ new NamedPipeClientStream ( "." , pipeName , PipeDirection . Out , PipeOptions . Asynchronous ) ;
674
719
}
675
720
676
721
public sealed class NamedPipeTest_ServerInOut_ClientInOut : NamedPipeStreamConformanceTests
677
722
{
678
- protected override ( NamedPipeServerStream Server , NamedPipeClientStream Client ) CreateServerAndClientStreams ( )
679
- {
680
- string pipeName = PipeStreamConformanceTests . GetUniquePipeName ( ) ;
681
- var server = new NamedPipeServerStream ( pipeName , PipeDirection . InOut , 1 , PipeTransmissionMode . Byte , PipeOptions . Asynchronous ) ;
682
- var client = new NamedPipeClientStream ( "." , pipeName , PipeDirection . InOut , PipeOptions . Asynchronous ) ;
683
- return ( server , client ) ;
684
- }
723
+ protected override NamedPipeServerStream CreateServerStream ( string pipeName , int maxInstances = 1 ) =>
724
+ new NamedPipeServerStream ( pipeName , PipeDirection . InOut , maxInstances , PipeTransmissionMode . Byte , PipeOptions . Asynchronous ) ;
725
+
726
+ protected override NamedPipeClientStream CreateClientStream ( string pipeName ) =>
727
+ new NamedPipeClientStream ( "." , pipeName , PipeDirection . InOut , PipeOptions . Asynchronous ) ;
685
728
}
686
729
}
0 commit comments