Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 69ac65b

Browse files
committed
Merge pull request #2899 from stephentoub/add_readasync_broken_test
Extend existing ReadFromPipeWithClosedPartner test for ReadAsync
2 parents c89033b + 69facdb commit 69ac65b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.Read.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ protected override ServerClientPair CreateServerClientPair()
6565

6666
// InOut pipes can be written/read from either direction
6767
public override void WriteToReadOnlyPipe_Throws_NotSupportedException() { }
68-
public override void ReadFromPipeWithClosedPartner_ReadNoBytes()
68+
public override async Task ReadFromPipeWithClosedPartner_ReadNoBytes()
6969
{
7070
// On Unix a read from an InOut pipe with a closed partner will wait indefinitely
7171
// for bytes to be sent.
7272
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
73-
base.ReadFromPipeWithClosedPartner_ReadNoBytes();
73+
await base.ReadFromPipeWithClosedPartner_ReadNoBytes();
7474
}
7575
}
7676
}

src/System.IO.Pipes/tests/PipeTest.Read.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,21 @@ public void ReadOnDisposedReadablePipe_Throws_ObjectDisposedException()
189189
}
190190

191191
[Fact]
192-
public virtual void ReadFromPipeWithClosedPartner_ReadNoBytes()
192+
public virtual async Task ReadFromPipeWithClosedPartner_ReadNoBytes()
193193
{
194194
using (ServerClientPair pair = CreateServerClientPair())
195195
{
196196
pair.writeablePipe.Dispose();
197197
byte[] buffer = new byte[] { 0, 0, 0, 0 };
198198

199-
int length = pair.readablePipe.Read(buffer, 0, buffer.Length);
200-
Assert.Equal(0, length);
201-
pair.readablePipe.ReadByte();
199+
// The pipe won't be marked as Broken until the first read, so prime it
200+
// to test both the case where it's not yet marked as "Broken" and then
201+
// where it is.
202+
Assert.Equal(0, pair.readablePipe.Read(buffer, 0, buffer.Length));
203+
204+
Assert.Equal(0, pair.readablePipe.Read(buffer, 0, buffer.Length));
205+
Assert.Equal(-1, pair.readablePipe.ReadByte());
206+
Assert.Equal(0, await pair.readablePipe.ReadAsync(buffer, 0, buffer.Length));
202207
}
203208
}
204209

0 commit comments

Comments
 (0)