@@ -397,5 +397,40 @@ public void InvalidReadMode_Throws_ArgumentOutOfRangeException(PipeDirection ser
397
397
Assert . Throws < ArgumentOutOfRangeException > ( ( ) => client . ReadMode = ( PipeTransmissionMode ) 999 ) ;
398
398
}
399
399
}
400
+
401
+ [ Fact ]
402
+ [ PlatformSpecific ( PlatformID . AnyUnix ) ]
403
+ public void Unix_MultipleServerDisposal_DoesntDeletePipe ( )
404
+ {
405
+ // Test for when multiple servers are created and linked to the same FIFO. The original ServerStream
406
+ // that created the FIFO is disposed. The other servers should still be valid and useable.
407
+ string serverName = GetUniquePipeName ( ) ;
408
+
409
+ var server1 = new NamedPipeServerStream ( serverName , PipeDirection . In ) ; // Creates the FIFO
410
+ var server2 = new NamedPipeServerStream ( serverName , PipeDirection . In ) ;
411
+ var client1 = new NamedPipeClientStream ( "." , serverName , PipeDirection . Out ) ;
412
+ var client2 = new NamedPipeClientStream ( "." , serverName , PipeDirection . Out ) ;
413
+
414
+ Task server1Task = server1 . WaitForConnectionAsync ( ) ; // Opens a handle to the FIFO
415
+ Task server2Task = server2 . WaitForConnectionAsync ( ) ; // Opens a handle to the same FIFO as server1
416
+
417
+ Task client1Task = client1 . ConnectAsync ( ) ;
418
+ Task . WaitAll ( server1Task , server2Task , client1Task ) ; // client1 connects to server1 AND server2
419
+
420
+ Assert . True ( server1 . IsConnected ) ;
421
+ Assert . True ( server2 . IsConnected ) ;
422
+
423
+ // Get rid of client1/server1 and make sure server2 isn't connected (so that it can connect to client2)
424
+ server1 . Dispose ( ) ;
425
+ client1 . Dispose ( ) ;
426
+ server2 . Disconnect ( ) ;
427
+ Assert . False ( server2 . IsConnected ) ;
428
+
429
+ server2Task = server2 . WaitForConnectionAsync ( ) ; // Opens a handle to the same FIFO
430
+ Task client2Task = client2 . ConnectAsync ( ) ;
431
+ Task . WaitAll ( server2Task , client2Task ) ; // Should not block!
432
+ Assert . True ( server2 . IsConnected ) ;
433
+ }
434
+
400
435
}
401
436
}
0 commit comments