Akka.Tests.Actor.LocalActorRefProviderSpec.An_ActorRefFactory_must_only_create_one_instance_of_an_actor_with_a_specific_address_in_a_concurrent_environment C# (CSharp) Метод

An_ActorRefFactory_must_only_create_one_instance_of_an_actor_with_a_specific_address_in_a_concurrent_environment() приватный Метод

        public void An_ActorRefFactory_must_only_create_one_instance_of_an_actor_with_a_specific_address_in_a_concurrent_environment()
        {
            var impl = (ActorSystemImpl)Sys;
            var provider = impl.Provider;

            Assert.IsType<LocalActorRefProvider>(provider);

            for (var i = 0; i < 100; i++)
            {
                var timeout = Dilated(TimeSpan.FromSeconds(5));
                var address = "new-actor" + i;
                var actors = Enumerable.Range(0, 4).Select(x => Task.Run(() => Sys.ActorOf(Props.Create(() => new BlackHoleActor()), address))).ToArray();
                // Use WhenAll with empty ContinueWith to swallow all exceptions, so we can inspect the tasks afterwards.
                Task.WhenAll(actors).ContinueWith(a => { }).Wait(timeout);
                Assert.True(actors.Any(x => x.Status == TaskStatus.RanToCompletion && x.Result != null), "Failed to create any Actors");
                Assert.True(actors.Any(x => x.Status == TaskStatus.Faulted && x.Exception.InnerException is InvalidActorNameException), "Succeeded in creating all Actors. Some should have failed.");
            }
        }