From 341b64fa28861123513ec546ec91cbbd86a8bc70 Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Wed, 27 Apr 2022 00:44:49 +0700 Subject: [PATCH 1/2] Convert Akka.Remote.Tests to async - RemoteRouterSpec --- .../Akka.Remote.Tests.csproj | 1 + .../Akka.Remote.Tests/RemoteRouterSpec.cs | 203 +++++++++--------- 2 files changed, 99 insertions(+), 105 deletions(-) diff --git a/src/core/Akka.Remote.Tests/Akka.Remote.Tests.csproj b/src/core/Akka.Remote.Tests/Akka.Remote.Tests.csproj index 2f5b6dd7a88..2ba434fb8c5 100644 --- a/src/core/Akka.Remote.Tests/Akka.Remote.Tests.csproj +++ b/src/core/Akka.Remote.Tests/Akka.Remote.Tests.csproj @@ -5,6 +5,7 @@ Akka.Remote.Tests $(NetFrameworkTestVersion);$(NetTestVersion);$(NetCoreTestVersion) + 8.0 diff --git a/src/core/Akka.Remote.Tests/RemoteRouterSpec.cs b/src/core/Akka.Remote.Tests/RemoteRouterSpec.cs index c724126af44..ab283fcbfdc 100644 --- a/src/core/Akka.Remote.Tests/RemoteRouterSpec.cs +++ b/src/core/Akka.Remote.Tests/RemoteRouterSpec.cs @@ -41,26 +41,22 @@ private class Parent : UntypedActor { protected override void OnReceive(object message) { - var tuple = message as (Props, string)?; - if (tuple != null) + if (message is ValueTuple tuple) { - Sender.Tell(Context.ActorOf(tuple.Value.Item1, tuple.Value.Item2)); + Sender.Tell(Context.ActorOf(tuple.Item1, tuple.Item2)); } } } - private Props EchoActorProps - { - get { return Props.Create(); } - } + private static Props EchoActorProps => Props.Create(); #endregion - private int port; - private string sysName; - private Config conf; - private ActorSystem masterSystem; - private Address intendedRemoteAddress; + private readonly int _port; + private readonly string _sysName; + private readonly Config _conf; + private readonly ActorSystem _masterSystem; + private readonly Address _intendedRemoteAddress; public RemoteRouterSpec(ITestOutputHelper output) : base(@" @@ -86,9 +82,9 @@ public RemoteRouterSpec(ITestOutputHelper output) ", output) { // ReSharper disable once PossibleInvalidOperationException - port = Sys.AsInstanceOf().Provider.DefaultAddress.Port.Value; - sysName = Sys.Name; - conf = ConfigurationFactory.ParseString(@" + _port = Sys.AsInstanceOf().Provider.DefaultAddress.Port.Value; + _sysName = Sys.Name; + _conf = ConfigurationFactory.ParseString(@" akka { actor.deployment { /blub { @@ -123,85 +119,82 @@ public RemoteRouterSpec(ITestOutputHelper output) } } } -".Replace("${masterSysName}", "Master" + sysName).Replace("${sysName}", sysName).Replace("${port}", port.ToString())).WithFallback(Sys.Settings.Config); +".Replace("${masterSysName}", "Master" + _sysName).Replace("${sysName}", _sysName).Replace("${port}", _port.ToString())).WithFallback(Sys.Settings.Config); - masterSystem = ActorSystem.Create("Master" + sysName, conf); + _masterSystem = ActorSystem.Create("Master" + _sysName, _conf); - intendedRemoteAddress = Address.Parse("akka.tcp://${sysName}@127.0.0.1:${port}" - .Replace("${sysName}", sysName) - .Replace("${port}", port.ToString())); + _intendedRemoteAddress = Address.Parse("akka.tcp://${sysName}@127.0.0.1:${port}" + .Replace("${sysName}", _sysName) + .Replace("${port}", _port.ToString())); } - protected override async Task AfterTerminationAsync() + protected override async Task AfterAllAsync() { - await ShutdownAsync(masterSystem); + await ShutdownAsync(_masterSystem); + await base.AfterAllAsync(); } - private IEnumerable CollectRouteePaths(TestProbe probe, IActorRef router, int n) + private async IAsyncEnumerable CollectRouteePaths(TestProbe probe, IActorRef router, int n) { - List list = new List(); - for (var i = 1; i <= n; i++) { - string msg = i.ToString(); + var msg = i.ToString(); router.Tell(msg, probe.Ref); - probe.ExpectMsg(msg); - list.Add(probe.LastSender.Path); + await probe.ExpectMsgAsync(msg); + yield return probe.LastSender.Path; } - - return list; } [Fact] - public void RemoteRouter_must_deploy_its_children_on_remote_host_driven_by_configuration() + public async Task RemoteRouter_must_deploy_its_children_on_remote_host_driven_by_configuration() { - var probe = CreateTestProbe(masterSystem); - var router = masterSystem.ActorOf(new RoundRobinPool(2).Props(EchoActorProps), "blub"); - var replies = CollectRouteePaths(probe, router, 5); + var probe = CreateTestProbe(_masterSystem); + var router = _masterSystem.ActorOf(new RoundRobinPool(2).Props(EchoActorProps), "blub"); + var replies = await CollectRouteePaths(probe, router, 5).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(2); children.Select(x => x.Parent).Distinct().Should().HaveCount(1); - children.ForEach(x => x.Address.Should().Be(intendedRemoteAddress)); - masterSystem.Stop(router); + children.ForEach(x => x.Address.Should().Be(_intendedRemoteAddress)); + _masterSystem.Stop(router); } [Fact] - public void RemoteRouter_must_deploy_its_children_on_remote_host_driven_by_programmatic_definition() + public async Task RemoteRouter_must_deploy_its_children_on_remote_host_driven_by_programmatic_definition() { - var probe = CreateTestProbe(masterSystem); - var router = masterSystem.ActorOf(new RemoteRouterConfig( + var probe = CreateTestProbe(_masterSystem); + var router = _masterSystem.ActorOf(new RemoteRouterConfig( new RoundRobinPool(2), - new[] { new Address("akka.tcp", sysName, "127.0.0.1", port) }) + new[] { new Address("akka.tcp", _sysName, "127.0.0.1", _port) }) .Props(EchoActorProps), "blub2"); - var replies = CollectRouteePaths(probe, router, 5); + var replies = await CollectRouteePaths(probe, router, 5).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(2); children.Select(x => x.Parent).Distinct().Should().HaveCount(1); - children.ForEach(x => x.Address.Should().Be(intendedRemoteAddress)); - masterSystem.Stop(router); + children.ForEach(x => x.Address.Should().Be(_intendedRemoteAddress)); + _masterSystem.Stop(router); } [Fact] - public void RemoteRouter_must_deploy_dynamic_resizable_number_of_children_on_remote_host_driven_by_configuration() + public async Task RemoteRouter_must_deploy_dynamic_resizable_number_of_children_on_remote_host_driven_by_configuration() { - var probe = CreateTestProbe(masterSystem); - var router = masterSystem.ActorOf(FromConfig.Instance.Props(EchoActorProps), "elastic-blub"); - var replies = CollectRouteePaths(probe, router, 5); + var probe = CreateTestProbe(_masterSystem); + var router = _masterSystem.ActorOf(FromConfig.Instance.Props(EchoActorProps), "elastic-blub"); + var replies = await CollectRouteePaths(probe, router, 5).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(2); children.Select(x => x.Parent).Distinct().Should().HaveCount(1); - children.ForEach(x => x.Address.Should().Be(intendedRemoteAddress)); - masterSystem.Stop(router); + children.ForEach(x => x.Address.Should().Be(_intendedRemoteAddress)); + _masterSystem.Stop(router); } [Fact] - public void RemoteRouter_must_deploy_remote_routers_based_on_configuration() + public async Task RemoteRouter_must_deploy_remote_routers_based_on_configuration() { - var probe = CreateTestProbe(masterSystem); - var router = masterSystem.ActorOf(FromConfig.Instance.Props(EchoActorProps), "remote-blub"); - router.Path.Address.Should().Be(intendedRemoteAddress); + var probe = CreateTestProbe(_masterSystem); + var router = _masterSystem.ActorOf(FromConfig.Instance.Props(EchoActorProps), "remote-blub"); + router.Path.Address.Should().Be(_intendedRemoteAddress); - var replies = CollectRouteePaths(probe, router, 5); + var replies = await CollectRouteePaths(probe, router, 5).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(2); @@ -209,21 +202,21 @@ public void RemoteRouter_must_deploy_remote_routers_based_on_configuration() parents.Should().HaveCount(1); parents.Head().Should().Be(router.Path); - children.ForEach(x => x.Address.Should().Be(intendedRemoteAddress)); - masterSystem.Stop(router); + children.ForEach(x => x.Address.Should().Be(_intendedRemoteAddress)); + _masterSystem.Stop(router); } [Fact] - public void RemoteRouter_must_deploy_remote_routers_based_on_explicit_deployment() + public async Task RemoteRouter_must_deploy_remote_routers_based_on_explicit_deployment() { - var probe = CreateTestProbe(masterSystem); - var router = masterSystem.ActorOf(new RoundRobinPool(2) + var probe = CreateTestProbe(_masterSystem); + var router = _masterSystem.ActorOf(new RoundRobinPool(2) .Props(EchoActorProps) - .WithDeploy(new Deploy(new RemoteScope(intendedRemoteAddress))), "remote-blub2"); + .WithDeploy(new Deploy(new RemoteScope(_intendedRemoteAddress))), "remote-blub2"); - router.Path.Address.Should().Be(intendedRemoteAddress); + router.Path.Address.Should().Be(_intendedRemoteAddress); - var replies = CollectRouteePaths(probe, router, 5); + var replies = await CollectRouteePaths(probe, router, 5).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(2); @@ -231,67 +224,67 @@ public void RemoteRouter_must_deploy_remote_routers_based_on_explicit_deployment parents.Should().HaveCount(1); parents.Head().Should().Be(router.Path); - children.ForEach(x => x.Address.Should().Be(intendedRemoteAddress)); - masterSystem.Stop(router); + children.ForEach(x => x.Address.Should().Be(_intendedRemoteAddress)); + _masterSystem.Stop(router); } [Fact] - public void RemoteRouter_must_let_remote_deployment_be_overridden_by_local_configuration() + public async Task RemoteRouter_must_let_remote_deployment_be_overridden_by_local_configuration() { - var probe = CreateTestProbe(masterSystem); - var router = masterSystem.ActorOf( + var probe = CreateTestProbe(_masterSystem); + var router = _masterSystem.ActorOf( new RoundRobinPool(2) .Props(EchoActorProps) - .WithDeploy(new Deploy(new RemoteScope(intendedRemoteAddress))), "local-blub"); - router.Path.Address.ToString().Should().Be($"akka://{masterSystem.Name}"); + .WithDeploy(new Deploy(new RemoteScope(_intendedRemoteAddress))), "local-blub"); + router.Path.Address.ToString().Should().Be($"akka://{_masterSystem.Name}"); - var replies = CollectRouteePaths(probe, router, 5); + var replies = await CollectRouteePaths(probe, router, 5).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(2); var parents = children.Select(x => x.Parent).Distinct().ToList(); parents.Should().HaveCount(1); - parents.Head().Address.Should().Be(new Address("akka.tcp", sysName, "127.0.0.1", port)); + parents.Head().Address.Should().Be(new Address("akka.tcp", _sysName, "127.0.0.1", _port)); - children.ForEach(x => x.Address.Should().Be(intendedRemoteAddress)); - masterSystem.Stop(router); + children.ForEach(x => x.Address.Should().Be(_intendedRemoteAddress)); + _masterSystem.Stop(router); } [Fact] - public void RemoteRouter_must_let_remote_deployment_router_be_overridden_by_local_configuration() + public async Task RemoteRouter_must_let_remote_deployment_router_be_overridden_by_local_configuration() { - var probe = CreateTestProbe(masterSystem); - var router = masterSystem.ActorOf( + var probe = CreateTestProbe(_masterSystem); + var router = _masterSystem.ActorOf( new RoundRobinPool(2) .Props(EchoActorProps) - .WithDeploy(new Deploy(new RemoteScope(intendedRemoteAddress))), "local-blub2"); + .WithDeploy(new Deploy(new RemoteScope(_intendedRemoteAddress))), "local-blub2"); - router.Path.Address.Should().Be(intendedRemoteAddress); + router.Path.Address.Should().Be(_intendedRemoteAddress); - var replies = CollectRouteePaths(probe, router, 5); + var replies = await CollectRouteePaths(probe, router, 5).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(4); var parents = children.Select(x => x.Parent).Distinct().ToList(); parents.Should().HaveCount(1); - parents.Head().Address.Should().Be(new Address("akka.tcp", sysName, "127.0.0.1", port)); + parents.Head().Address.Should().Be(new Address("akka.tcp", _sysName, "127.0.0.1", _port)); - children.ForEach(x => x.Address.Should().Be(intendedRemoteAddress)); - masterSystem.Stop(router); + children.ForEach(x => x.Address.Should().Be(_intendedRemoteAddress)); + _masterSystem.Stop(router); } [Fact] - public void RemoteRouter_must_let_remote_deployment_be_overridden_by_remote_configuration() + public async Task RemoteRouter_must_let_remote_deployment_be_overridden_by_remote_configuration() { - var probe = CreateTestProbe(masterSystem); - var router = masterSystem.ActorOf( + var probe = CreateTestProbe(_masterSystem); + var router = _masterSystem.ActorOf( new RoundRobinPool(2) .Props(EchoActorProps) - .WithDeploy(new Deploy(new RemoteScope(intendedRemoteAddress))), "remote-override"); + .WithDeploy(new Deploy(new RemoteScope(_intendedRemoteAddress))), "remote-override"); - router.Path.Address.Should().Be(intendedRemoteAddress); + router.Path.Address.Should().Be(_intendedRemoteAddress); - var replies = CollectRouteePaths(probe, router, 5); + var replies = await CollectRouteePaths(probe, router, 5).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(4); @@ -299,57 +292,57 @@ public void RemoteRouter_must_let_remote_deployment_be_overridden_by_remote_conf parents.Should().HaveCount(1); parents.Head().Address.Should().Be(router.Path.Address); - children.ForEach(x => x.Address.Should().Be(intendedRemoteAddress)); - masterSystem.Stop(router); + children.ForEach(x => x.Address.Should().Be(_intendedRemoteAddress)); + _masterSystem.Stop(router); } [Fact] public async Task RemoteRouter_must_set_supplied_SupervisorStrategy() { - var probe = CreateTestProbe(masterSystem); + var probe = CreateTestProbe(_masterSystem); var escalator = new OneForOneStrategy(ex => { probe.Ref.Tell(ex); return Directive.Escalate; }); - var router = masterSystem.ActorOf(new RemoteRouterConfig( + var router = _masterSystem.ActorOf(new RemoteRouterConfig( new RoundRobinPool(1, null, escalator, Dispatchers.DefaultDispatcherId), - new[] { new Address("akka.tcp", sysName, "127.0.0.1", port) }).Props(Props.Empty), "blub3"); + new[] { new Address("akka.tcp", _sysName, "127.0.0.1", _port) }).Props(Props.Empty), "blub3"); router.Tell(new GetRoutees(), probe.Ref); // Need to be able to bind EventFilter to additional actor system (masterActorSystem in this case) before this code works // EventFilter.Exception().ExpectOne(() => - probe.ExpectMsg(TimeSpan.FromSeconds(10)).Members.Head().Send(Kill.Instance, TestActor); + (await probe.ExpectMsgAsync(TimeSpan.FromSeconds(10))).Members.Head().Send(Kill.Instance, TestActor); //); - probe.ExpectMsg(TimeSpan.FromSeconds(10)); + await probe.ExpectMsgAsync(TimeSpan.FromSeconds(10)); } [Fact(Skip = "Remote actor's DCN is currently not supported")] - public void RemoteRouter_must_load_settings_from_config_for_local_router() + public async Task RemoteRouter_must_load_settings_from_config_for_local_router() { - var probe = CreateTestProbe(masterSystem); - var router = masterSystem.ActorOf(FromConfig.Instance.Props(EchoActorProps), "round"); - var replies = CollectRouteePaths(probe, router, 10); + var probe = CreateTestProbe(_masterSystem); + var router = _masterSystem.ActorOf(FromConfig.Instance.Props(EchoActorProps), "round"); + var replies = await CollectRouteePaths(probe, router, 10).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(5); - masterSystem.Stop(router); + _masterSystem.Stop(router); } [Fact(Skip = "Remote actor's DCN is currently not supported")] - public void RemoteRouter_must_load_settings_from_config_for_local_child_router_of_system_actor() + public async Task RemoteRouter_must_load_settings_from_config_for_local_child_router_of_system_actor() { // we don't really support deployment configuration of system actors, but // it's used for the pool of the SimpleDnsManager "/IO-DNS/inet-address" - var probe = CreateTestProbe(masterSystem); - var parent = ((ExtendedActorSystem)masterSystem).SystemActorOf(FromConfig.Instance.Props(Props.Create()), "sys-parent"); + var probe = CreateTestProbe(_masterSystem); + var parent = ((ExtendedActorSystem)_masterSystem).SystemActorOf(FromConfig.Instance.Props(Props.Create()), "sys-parent"); parent.Tell((FromConfig.Instance.Props(EchoActorProps), "round"), probe); var router = probe.ExpectMsg(); - var replies = CollectRouteePaths(probe, router, 10); + var replies = await CollectRouteePaths(probe, router, 10).ToListAsync(); var children = new HashSet(replies); children.Should().HaveCount(6); - masterSystem.Stop(router); + _masterSystem.Stop(router); } } } From 64907d9c611cd1067e1bd0058408fcff8704824c Mon Sep 17 00:00:00 2001 From: Gregorius Soedharmo Date: Thu, 28 Apr 2022 04:34:17 +0700 Subject: [PATCH 2/2] Remove net471 from target platform, IAsyncEnumerator is not compatible in linux builds --- src/core/Akka.Remote.Tests/Akka.Remote.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Akka.Remote.Tests/Akka.Remote.Tests.csproj b/src/core/Akka.Remote.Tests/Akka.Remote.Tests.csproj index 2ba434fb8c5..ac0ad2efcfc 100644 --- a/src/core/Akka.Remote.Tests/Akka.Remote.Tests.csproj +++ b/src/core/Akka.Remote.Tests/Akka.Remote.Tests.csproj @@ -4,7 +4,7 @@ Akka.Remote.Tests - $(NetFrameworkTestVersion);$(NetTestVersion);$(NetCoreTestVersion) + $(NetTestVersion);$(NetCoreTestVersion) 8.0