Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.Communication.Tests/ActiveNodeEvaluatorTests.cs
T
Joseph Doherty 513fa1aa16 docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)
Comment/XML-doc changes only:
- add summaries to ~10k test methods, fixtures, fakes and helpers
  (+ <param> on theories, <returns> on async Task methods,
  <inheritdoc/> on interface implementations the checker can resolve)
- strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N,
  #NN, Component-0NN) from comments, keeping the explanatory text;
  reword false positives in comments only
- real docs on fakes implementing BCL/library interfaces
  (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime)
- reword the last 5 src/ false positives (CWE-1236, failures-1,
  year-0001, M365)

Only non-comment edits: four one-line nested classes split across lines
so members can carry docs. Build 0 errors / 0 warnings.
2026-10-07 15:05:49 -04:00

64 lines
2.3 KiB
C#

using System.Net;
using System.Net.Sockets;
using Akka.Actor;
using Akka.Configuration;
using Xunit;
using ZB.MOM.WW.ScadaBridge.Communication.ClusterState;
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
public class ActiveNodeEvaluatorTests : IAsyncLifetime
{
private ActorSystem? _system;
/// <summary>Starts the test actor system and cluster before the tests run.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
public async Task InitializeAsync()
{
var port = FreePort();
var config = ConfigurationFactory.ParseString($@"
akka {{
actor.provider = cluster
remote.dot-netty.tcp {{ hostname = ""127.0.0.1"", port = {port} }}
cluster {{
seed-nodes = [""akka.tcp://ane-test@127.0.0.1:{port}""]
roles = [""site-x""]
min-nr-of-members = 1
}}
}}");
_system = ActorSystem.Create("ane-test", config);
var cluster = Akka.Cluster.Cluster.Get(_system);
var deadline = DateTime.UtcNow.AddSeconds(20);
while (cluster.SelfMember.Status != Akka.Cluster.MemberStatus.Up && DateTime.UtcNow < deadline)
await Task.Delay(100);
}
/// <summary>Terminates the test actor system.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
public async Task DisposeAsync() { if (_system != null) await _system.Terminate(); }
/// <summary>Verifies that the sole Up member is considered the oldest Up member.</summary>
[Fact]
public void SelfIsOldestUp_SoleUpMember_ReturnsTrue()
{
var cluster = Akka.Cluster.Cluster.Get(_system!);
Assert.True(ActiveNodeEvaluator.SelfIsOldestUp(cluster));
Assert.True(ActiveNodeEvaluator.SelfIsOldestUp(cluster, "site-x"));
}
/// <summary>Verifies that a node that does not hold the requested role is not considered the oldest Up member.</summary>
[Fact]
public void SelfIsOldestUp_RoleNotHeld_ReturnsFalse()
{
var cluster = Akka.Cluster.Cluster.Get(_system!);
Assert.False(ActiveNodeEvaluator.SelfIsOldestUp(cluster, "role-nonexistent"));
}
private static int FreePort()
{
using var l = new TcpListener(IPAddress.Loopback, 0);
l.Start();
return ((IPEndPoint)l.LocalEndpoint).Port;
}
}