From 87cf9302724612d1c88a37f8396ed6ac2ccdcda4 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 7 Jun 2019 07:24:21 -0700 Subject: [PATCH] Don't throw in the On* callbacks (dotnet/corefx#38327) - We can't throw NotSupportedException in the OnWriterCompleted and OnReaderCompleted callbacks since consumers of the API won't know if it's safe to do so. We could add a SupportsOn* boolean but nooping is a much simpler solution without breaking existing callers. We can also add a boolean in the future so callers will know when they can register callbacks or not. Commit migrated from https://github.com/dotnet/corefx/commit/672cc2c985d1f6f00afe853e678ed05de9757724 --- .../System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs | 2 -- .../System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs | 1 - src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs | 5 +++-- src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs | 4 +++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs index 9f1e292..c7c2908 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs @@ -186,8 +186,6 @@ namespace System.IO.Pipelines /// public override void OnWriterCompleted(Action callback, object state) { - // REVIEW: Do we fire this when the stream has ended? - throw new NotSupportedException("OnWriterCompleted is not supported"); } /// diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs index 9b61d3e..6014c47 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs @@ -232,7 +232,6 @@ namespace System.IO.Pipelines /// public override void OnReaderCompleted(Action callback, object state) { - throw new NotSupportedException("OnReaderCompleted is not supported."); } /// diff --git a/src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs b/src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs index fd0d658..0f3ea22 100644 --- a/src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs +++ b/src/libraries/System.IO.Pipelines/tests/StreamPipeReaderTests.cs @@ -484,10 +484,11 @@ namespace System.IO.Pipelines.Tests [Fact] public void OnWriterCompletedThrowsNotSupportedException() { + bool fired = false; PipeReader reader = PipeReader.Create(Stream.Null); - - Assert.Throws(() => reader.OnWriterCompleted((_, __) => { }, null)); + reader.OnWriterCompleted((_, __) => { fired = true; }, null); reader.Complete(); + Assert.False(fired); } [Fact] diff --git a/src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs b/src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs index f76bbdb..4dc13e4 100644 --- a/src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs +++ b/src/libraries/System.IO.Pipelines/tests/StreamPipeWriterTests.cs @@ -453,9 +453,11 @@ namespace System.IO.Pipelines.Tests [Fact] public void OnReaderCompletedThrowsNotSupported() { + bool fired = false; PipeWriter writer = PipeWriter.Create(Stream.Null); - Assert.Throws(() => writer.OnReaderCompleted((_, __) => { }, null)); + writer.OnReaderCompleted((_, __) => { fired = true; }, null); writer.Complete(); + Assert.False(fired); } private class FlushAsyncAwareStream : WriteOnlyStream -- 2.7.4