From 856f0f62d37686010c63dd891ccda8b092ebb031 Mon Sep 17 00:00:00 2001 From: genietonic Date: Thu, 8 Apr 2021 10:42:03 +0300 Subject: [PATCH] Fixed System.ArgumentNullException in Interspase operation on empty stream finish. --- .../Dsl/FlowIntersperseSpec.cs | 26 +++++++++++++++++++ .../Akka.Streams/Implementation/Fusing/Ops.cs | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/core/Akka.Streams.Tests/Dsl/FlowIntersperseSpec.cs b/src/core/Akka.Streams.Tests/Dsl/FlowIntersperseSpec.cs index af0372c4e44..c950002fdd0 100644 --- a/src/core/Akka.Streams.Tests/Dsl/FlowIntersperseSpec.cs +++ b/src/core/Akka.Streams.Tests/Dsl/FlowIntersperseSpec.cs @@ -102,6 +102,32 @@ public void A_Intersperse_must_surround_single_element_stream_with_start_and_end probe.ExpectSubscription(); probe.ToStrict(TimeSpan.FromSeconds(1)).Aggregate((s, s1) => s + s1).Should().Be("[1]"); } + + [Fact] + public void A_Intersperse_must_not_surround_empty_stream_with_null_start_and_stop() + { + var probe = + Source.From(new int[0]) + .Select(x => x.ToString()) + .Intersperse(",") + .RunWith(this.SinkProbe(), Materializer); + + probe.ExpectSubscription(); + probe.ToStrict(TimeSpan.FromSeconds(1)).Count().Should().Be(0); + } + + [Fact] + public void A_Intersperse_must_not_surround_single_element_stream_with_null_start_and_stop() + { + var probe = + Source.From(new int[]{1}) + .Select(x => x.ToString()) + .Intersperse(",") + .RunWith(this.SinkProbe(), Materializer); + + probe.ExpectSubscription(); + probe.ToStrict(TimeSpan.FromSeconds(1)).Aggregate((s, s1) => s + s1).Should().Be("1"); + } [Fact] public void A_Intersperse_must__complete_the_stage_when_the_Source_has_been_completed() diff --git a/src/core/Akka.Streams/Implementation/Fusing/Ops.cs b/src/core/Akka.Streams/Implementation/Fusing/Ops.cs index 40b1865fcc9..833c704bde2 100644 --- a/src/core/Akka.Streams/Implementation/Fusing/Ops.cs +++ b/src/core/Akka.Streams/Implementation/Fusing/Ops.cs @@ -1518,7 +1518,7 @@ public override void OnPush() public override void OnUpstreamFinish() { - _logic.EmitMultiple(_stage.Outlet, new[] { _stage._start, _stage._end }); + if (_stage.InjectStartEnd) _logic.EmitMultiple(_stage.Outlet, new[] { _stage._start, _stage._end }); _logic.CompleteStage(); } }