public async Task ReadCanBeCanceledViaCancelPendingReadWhenReadIsAsync() { var pipeReader = new StreamPipeReader(new HangingStream()); var result = new ReadResult(); var tcs = new TaskCompletionSource <int>(TaskCreationOptions.RunContinuationsAsynchronously); var task = Task.Run(async() => { var readingTask = pipeReader.ReadAsync(); tcs.SetResult(0); result = await readingTask; }); await tcs.Task; pipeReader.CancelPendingRead(); await task; Assert.True(result.IsCanceled); }