Akka.Streams.Tests.Dsl.SubstreamSubscriptionTimeoutSpec.GroupBy_and_SplitWhen_must_timeout_and_cancel_substream_publisher_when_no_one_subscribes_to_them_after_some_time C# (CSharp) Method

GroupBy_and_SplitWhen_must_timeout_and_cancel_substream_publisher_when_no_one_subscribes_to_them_after_some_time() private method

        public void GroupBy_and_SplitWhen_must_timeout_and_cancel_substream_publisher_when_no_one_subscribes_to_them_after_some_time()
        {
            this.AssertAllStagesStopped(() =>
            {
                var subscriber = TestSubscriber.CreateManualProbe<Tuple<int, Source<int, NotUsed>>>(this);
                var publisherProbe = TestPublisher.CreateProbe<int>(this);
                var publisher =
                    Source.FromPublisher(publisherProbe)
                        .GroupBy(3, x => x%3)
                        .Lift(x => x%3)
                        .RunWith(Sink.FromSubscriber(subscriber), Materializer);

                var downstreamSubscription = subscriber.ExpectSubscription();
                downstreamSubscription.Request(100);

                publisherProbe.SendNext(1);
                publisherProbe.SendNext(2);
                publisherProbe.SendNext(3);

                var s1 = subscriber.ExpectNext().Item2;
                // should not break normal usage
                var s1SubscriberProbe = TestSubscriber.CreateManualProbe<int>(this);
                s1.RunWith(Sink.FromSubscriber(s1SubscriberProbe), Materializer);
                var s1Subscription = s1SubscriberProbe.ExpectSubscription();
                s1Subscription.Request(100);
                s1SubscriberProbe.ExpectNext().Should().Be(1);

                var s2 = subscriber.ExpectNext().Item2;
                // should not break normal usage
                var s2SubscriberProbe = TestSubscriber.CreateManualProbe<int>(this);
                s2.RunWith(Sink.FromSubscriber(s2SubscriberProbe), Materializer);
                var s2Subscription = s2SubscriberProbe.ExpectSubscription();
                s2Subscription.Request(100);
                s2SubscriberProbe.ExpectNext().Should().Be(2);

                var s3 = subscriber.ExpectNext().Item2;

                // sleep long enough for it to be cleaned up
                Thread.Sleep(1500);

                // Must be a Sink.seq, otherwise there is a race due to the concat in the `lift` implementation
                Action action = () => s3.RunWith(Sink.Seq<int>(), Materializer).Wait(TimeSpan.FromMilliseconds(300));
                action.ShouldThrow<SubscriptionTimeoutException>();

                publisherProbe.SendComplete();
            }, Materializer);
        }