Merge #590: ClusterRoleInfo records the RoleLeaderChanged address directly (lagging State snapshot could pin a role leader to null)
Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
@@ -126,4 +126,43 @@ public sealed class ClusterRoleInfoRoleLeaderCaseTests
|
||||
hostA.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deterministic pin for Gitea #590: a RoleLeaderChanged event whose leader address is not (yet)
|
||||
/// in <c>Cluster.State.Members</c> must still record that leader. The handler used to resolve the
|
||||
/// address through the state snapshot, which is published asynchronously and can lag the event;
|
||||
/// a miss stored null permanently. Here the cluster never joins anything, so the leader address
|
||||
/// is guaranteed absent from the snapshot — the lagging-snapshot case, made exact.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task RoleLeaderChanged_is_recorded_even_when_the_leader_is_not_in_the_state_snapshot()
|
||||
{
|
||||
var port = FreePort();
|
||||
var options = new AkkaClusterOptions
|
||||
{
|
||||
SystemName = SystemName, Hostname = "127.0.0.1", PublicHostname = "127.0.0.1",
|
||||
Port = port, Roles = new[] { "driver" }, SeedNodes = Array.Empty<string>(),
|
||||
};
|
||||
var system = Akka.Actor.ActorSystem.Create(SystemName, Akka.Configuration.ConfigurationFactory.ParseString(
|
||||
"akka.actor.provider = cluster\nakka.remote.dot-netty.tcp.hostname = 127.0.0.1\n"
|
||||
+ $"akka.remote.dot-netty.tcp.port = {port}"));
|
||||
try
|
||||
{
|
||||
using var info = new ClusterRoleInfo(
|
||||
system, Options.Create(options),
|
||||
Microsoft.Extensions.Logging.Abstractions.NullLogger<ClusterRoleInfo>.Instance);
|
||||
var driver = new Akka.Actor.Address("akka.tcp", SystemName, "127.0.0.1", 11111);
|
||||
var capital = new Akka.Actor.Address("akka.tcp", SystemName, "127.0.0.1", 22222);
|
||||
|
||||
info.HandleRoleLeaderChanged(new Akka.Cluster.ClusterEvent.RoleLeaderChanged("driver", driver));
|
||||
info.HandleRoleLeaderChanged(new Akka.Cluster.ClusterEvent.RoleLeaderChanged("Driver", capital));
|
||||
|
||||
info.RoleLeader("driver")!.Value.ToString().ShouldContain("11111");
|
||||
info.RoleLeader("Driver")!.Value.ToString().ShouldContain("22222");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await system.Terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user