private int ReadInternal(Span<byte> buffer)
{
ValueTask<ReadResult> vt = _pipeReader.ReadAsync();
- ReadResult result = vt.IsCompletedSuccessfully ? vt.Result : vt.AsTask().Result;
+ ReadResult result = vt.IsCompletedSuccessfully ? vt.Result : vt.AsTask().GetAwaiter().GetResult();
return HandleReadResult(result, buffer);
}
Assert.Equal(producedSum, consumedSum);
}
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+ public void ReadThrowsOriginalExceptionWhenItOccurs()
+ {
+ var pipeReader = new BuggyAndNotCompletedPipeReader();
+ Stream stream = pipeReader.AsStream();
+ AssertExtensions.Throws<InvalidOperationException>(() => stream.Read(new byte[3], 0, 3), "error occured during reading");
+ }
+
[Fact]
public void AsStreamDoNotCompleteReader()
{
yield return new object[] { readSpanSync };
}
}
+
+ public class BuggyAndNotCompletedPipeReader : BuggyPipeReader
+ {
+ public override ValueTask<ReadResult> ReadAsync(CancellationToken cancellationToken = default) =>
+ new ValueTask<ReadResult>(Task.FromException<ReadResult>(new InvalidOperationException("error occured during reading")));
+ }
}
}