From d943e140c4fd2866c504ca04d506f3976404c1cd Mon Sep 17 00:00:00 2001 From: Roger Johansson Date: Sun, 3 Aug 2025 15:17:59 +0200 Subject: [PATCH] test: expand process registry coverage --- .../Proto.Actor.Tests/ProcessRegistryTests.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/Proto.Actor.Tests/ProcessRegistryTests.cs b/tests/Proto.Actor.Tests/ProcessRegistryTests.cs index fb492e3c85..c8bc98e004 100644 --- a/tests/Proto.Actor.Tests/ProcessRegistryTests.cs +++ b/tests/Proto.Actor.Tests/ProcessRegistryTests.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Threading.Tasks; using Proto.TestFixtures; using Xunit; @@ -87,4 +88,50 @@ public async Task Given_PIDExistsInHostResolver_GetShouldReturnIt() Assert.Same(p, p2); } + + [Fact] + public async Task Given_ProcessRegistry_NextIdShouldReturnSequentialIds() + { + var system = new ActorSystem(); + await using var _ = system; + var reg = new ProcessRegistry(system); + + var id1 = reg.NextId(); + var id2 = reg.NextId(); + + Assert.Equal("$1", id1); + Assert.Equal("$2", id2); + } + + [Fact] + public async Task Given_PIDs_FindShouldReturnMatchingPIDs() + { + var system = new ActorSystem(); + await using var _ = system; + var reg = new ProcessRegistry(system); + var p1 = new TestProcess(system); + var p2 = new TestProcess(system); + var p3 = new TestProcess(system); + reg.TryAdd("alpha", p1); + reg.TryAdd("beta", p2); + reg.TryAdd("ALPHANUM", p3); + + var results = reg.Find("Alp").ToList(); + + Assert.Equal(2, results.Count); + Assert.All(results, pid => Assert.Equal(system.Address, pid.Address)); + Assert.Contains(results, pid => pid.Id == "alpha"); + Assert.Contains(results, pid => pid.Id == "ALPHANUM"); + } + + [Fact] + public async Task Given_RemotePIDWithoutResolver_GetShouldThrow() + { + var system = new ActorSystem(); + await using var _ = system; + var reg = new ProcessRegistry(system); + var pid = PID.FromAddress("remote", "123"); + + Assert.Throws(() => reg.Get(pid)); + } }