public void SplitWhen_must_support_cancelling_both_master_and_substream()
{
this.AssertAllStagesStopped(() =>
{
var inputs = TestPublisher.CreateProbe<int>(this);
var substream = TestSubscriber.CreateProbe<int>(this);
var masterStream = TestSubscriber.CreateProbe<NotUsed>(this);
Source.FromPublisher(inputs)
.SplitWhen(x => x == 2)
.Lift()
.Select(x => x.RunWith(Sink.FromSubscriber(substream), Materializer))
.RunWith(Sink.FromSubscriber(masterStream), Materializer);
masterStream.Request(1);
inputs.SendNext(1);
substream.Cancel();
masterStream.ExpectNext(NotUsed.Instance);
masterStream.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
masterStream.Cancel();
inputs.ExpectCancellation();
var inputs2 = TestPublisher.CreateProbe<int>(this);
Source.FromPublisher(inputs2)
.SplitWhen(x => x == 2)
.Lift()
.Select(x => x.RunWith(Sink.Cancelled<int>(), Materializer))
.RunWith(Sink.Cancelled<NotUsed>(), Materializer);
inputs2.ExpectCancellation();
var inputs3 = TestPublisher.CreateProbe<int>(this);
var masterStream3 = TestSubscriber.CreateProbe<Source<int, NotUsed>>(this);
Source.FromPublisher(inputs3)
.SplitWhen(x => x == 2)
.Lift()
.RunWith(Sink.FromSubscriber(masterStream3), Materializer);
masterStream3.Request(1);
inputs3.SendNext(1);
var src = masterStream3.ExpectNext();
src.RunWith(Sink.Cancelled<int>(), Materializer);
masterStream3.Request(1);
inputs3.SendNext(2);
var src2 = masterStream3.ExpectNext();
var substream4 = TestSubscriber.CreateProbe<int>(this);
src2.RunWith(Sink.FromSubscriber(substream4), Materializer);
substream4.RequestNext(2);
substream4.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
masterStream3.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
inputs3.ExpectRequest();
inputs3.ExpectRequest();
inputs3.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
substream4.Cancel();
inputs3.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
masterStream3.ExpectNoMsg(TimeSpan.FromMilliseconds(100));
masterStream3.Cancel();
inputs3.ExpectCancellation();
}, Materializer);
}