Unix: System.IO.Pipes; Disconnected pipe not throwing exceptions on other side of pipe
[Fact]
public static void ClientDisconnectedPipeThrows()
{
using (NamedPipeServerStream server = new NamedPipeServerStream("testServer2", PipeDirection.InOut))
{
using (NamedPipeClientStream client = new NamedPipeClientStream("testServer2"))
{
byte[] buffer = new byte[] { 0, 0, 0, 0 };
Task clientConnect1 = client.ConnectAsync();
server.WaitForConnection();
clientConnect1.Wait();
Assert.True(client.IsConnected);
Assert.True(server.IsConnected);
client.Dispose();
Assert.Throws<IOException>(() => server.Write(buffer, 0, buffer.Length));
Assert.Throws<IOException>(() => server.WriteByte(123));
Assert.Throws<IOException>(() => server.Flush());
int length = server.Read(buffer, 0, buffer.Length);
Assert.Equal(0, length);
int byt = server.ReadByte();
}
}
}
[Fact]
public static void ServerDisconnectedPipeThrows()
{
using (NamedPipeServerStream server = new NamedPipeServerStream("testServer3", PipeDirection.InOut))
{
using (NamedPipeClientStream client = new NamedPipeClientStream("testServer3"))
{
byte[] buffer = new byte[] { 0, 0, 0, 0 };
Task clientConnect1 = client.ConnectAsync();
server.WaitForConnection();
clientConnect1.Wait();
Assert.True(client.IsConnected);
Assert.True(server.IsConnected);
server.Dispose();
Assert.Throws<IOException>(() => client.Write(buffer, 0, buffer.Length));
Assert.Throws<IOException>(() => client.WriteByte(123));
Assert.Throws<IOException>(() => client.Flush());
int length = client.Read(buffer, 0, buffer.Length);
Assert.Equal(0, length);
int byt = client.ReadByte();
}
}
}
13:30:03 �[31m System.IO.Pipes.Tests.NamedPipesThrowsTests.ClientDisconnectedPipeThrows [FAIL] 13:30:03 �[37m Assert.Throws() Failure 13:30:03 Expected: typeof(System.IO.IOException) 13:30:03 Actual: (No exception was thrown) 13:30:03 �[30m Stack Trace: 13:30:03 �[37m at System.IO.Pipes.Tests.NamedPipesThrowsTests.ClientDisconnectedPipeThrows() 13:30:03 �[31m System.IO.Pipes.Tests.NamedPipesThrowsTests.ServerDisconnectedPipeThrows [FAIL] 13:30:03 �[37m Assert.Throws() Failure 13:30:03 Expected: typeof(System.IO.IOException) 13:30:03 Actual: (No exception was thrown) 13:30:03 �[30m Stack Trace: 13:30:03 �[37m at System.IO.Pipes.Tests.NamedPipesThrowsTests.ServerDisconnectedPipeThrows()
Fixed by dotnet/corefx#1884