From 79111249e08fd46ef47aa7d028568793677495b6 Mon Sep 17 00:00:00 2001 From: Roger Johansson Date: Sat, 4 Jun 2022 23:05:25 +0200 Subject: [PATCH 1/2] . --- src/Proto.Actor/Context/SystemContext.cs | 6 ++++++ tests/Proto.Cluster.Tests/PubSubTests.cs | 18 +++++------------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Proto.Actor/Context/SystemContext.cs b/src/Proto.Actor/Context/SystemContext.cs index 467de771df..58f693312e 100644 --- a/src/Proto.Actor/Context/SystemContext.cs +++ b/src/Proto.Actor/Context/SystemContext.cs @@ -14,6 +14,12 @@ public static class SystemContext public static PID SpawnNamedSystem(this RootContext self, Props props, string name) { + if (!name.StartsWith("$")) + { + Logger.LogError("SystemContext Failed to spawn system actor {Name}", name); + throw new ArgumentException("System actor names must start with $", nameof(name)); + } + try { var parent = props.GuardianStrategy is not null diff --git a/tests/Proto.Cluster.Tests/PubSubTests.cs b/tests/Proto.Cluster.Tests/PubSubTests.cs index 34828cc1d3..a8dc01727a 100644 --- a/tests/Proto.Cluster.Tests/PubSubTests.cs +++ b/tests/Proto.Cluster.Tests/PubSubTests.cs @@ -187,7 +187,7 @@ private async Task SubscribeAllTo(string topic, string[] subscriberIds) { foreach (var id in subscriberIds) { - await SubscribeTo(topic, id); + await _fixture.Members.First().Subscribe(topic, ClusterIdentity.Create(id, PubSubInMemoryClusterFixture.SubscriberKind)); } } @@ -195,7 +195,7 @@ private async Task UnsubscribeAllFrom(string topic, string[] subscriberIds) { foreach (var id in subscriberIds) { - await UnsubscribeFrom(topic, id); + await _fixture.Members.First().Unsubscribe(topic, ClusterIdentity.Create(id, PubSubInMemoryClusterFixture.SubscriberKind)); } } @@ -256,7 +256,7 @@ public PubSubInMemoryClusterFixture() : base(3) private Props SubscriberProps() { - async Task Receive(IContext context) + Task Receive(IContext context) { switch (context.Message) { @@ -264,17 +264,9 @@ async Task Receive(IContext context) Deliveries.Add(new Delivery(context.ClusterIdentity()!.Identity, msg.Data)); context.Respond(new Response()); break; - - case Subscribe msg: - await context.Cluster().Subscribe(msg.Topic, context.ClusterIdentity()!); - context.Respond(new Response()); - break; - - case Unsubscribe msg: - await context.Cluster().Unsubscribe(msg.Topic, context.ClusterIdentity()!); - context.Respond(new Response()); - break; } + + return Task.CompletedTask; } return Props.FromFunc(Receive); From 339f0cf02144c5688915e34f14a4654ce5f5e788 Mon Sep 17 00:00:00 2001 From: Roger Johansson Date: Sat, 4 Jun 2022 23:52:11 +0200 Subject: [PATCH 2/2] . --- tests/Proto.Cluster.Tests/PubSubTests.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/Proto.Cluster.Tests/PubSubTests.cs b/tests/Proto.Cluster.Tests/PubSubTests.cs index a8dc01727a..6285729481 100644 --- a/tests/Proto.Cluster.Tests/PubSubTests.cs +++ b/tests/Proto.Cluster.Tests/PubSubTests.cs @@ -187,7 +187,7 @@ private async Task SubscribeAllTo(string topic, string[] subscriberIds) { foreach (var id in subscriberIds) { - await _fixture.Members.First().Subscribe(topic, ClusterIdentity.Create(id, PubSubInMemoryClusterFixture.SubscriberKind)); + await SubscribeTo(topic, id); } } @@ -195,7 +195,7 @@ private async Task UnsubscribeAllFrom(string topic, string[] subscriberIds) { foreach (var id in subscriberIds) { - await _fixture.Members.First().Unsubscribe(topic, ClusterIdentity.Create(id, PubSubInMemoryClusterFixture.SubscriberKind)); + await UnsubscribeFrom(topic, id); } } @@ -256,7 +256,7 @@ public PubSubInMemoryClusterFixture() : base(3) private Props SubscriberProps() { - Task Receive(IContext context) + async Task Receive(IContext context) { switch (context.Message) { @@ -264,9 +264,16 @@ Task Receive(IContext context) Deliveries.Add(new Delivery(context.ClusterIdentity()!.Identity, msg.Data)); context.Respond(new Response()); break; - } + case Subscribe msg: + await context.Cluster().Subscribe(msg.Topic, context.ClusterIdentity()!); + context.Respond(new Response()); + break; - return Task.CompletedTask; + case Unsubscribe msg: + await context.Cluster().Unsubscribe(msg.Topic, context.ClusterIdentity()!); + context.Respond(new Response()); + break; + } } return Props.FromFunc(Receive);