Exemplo n.º 1
0
        public static T AssertAllStagesStopped <T>(this AkkaSpec spec, Func <T> block, IMaterializer materializer)
        {
            var impl = materializer as ActorMaterializerImpl;

            if (impl == null)
            {
                return(block());
            }

            var probe = spec.CreateTestProbe(impl.System);

            probe.Send(impl.Supervisor, StreamSupervisor.StopChildren.Instance);
            probe.ExpectMsg <StreamSupervisor.StoppedChildren>();
            var result = block();

            probe.Within(TimeSpan.FromSeconds(5), () =>
            {
                IImmutableSet <IActorRef> children = ImmutableHashSet <IActorRef> .Empty;
                try
                {
                    probe.AwaitAssert(() =>
                    {
                        impl.Supervisor.Tell(StreamSupervisor.GetChildren.Instance, probe.Ref);
                        children = probe.ExpectMsg <StreamSupervisor.Children>().Refs;
                        if (children.Count != 0)
                        {
                            throw new Exception($"expected no StreamSupervisor children, but got {children.Aggregate("", (s, @ref) => s + @ref + ", ")}");
                        }
                    });
                }
                catch
                {
                    children.ForEach(c => c.Tell(StreamSupervisor.PrintDebugDump.Instance));
                    throw;
                }
            });

            return(result);
        }