64e3fbe035
v2-ci / build (push) Failing after 1m43s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
Adds <summary>, <param>, <typeparam>, and <inheritdoc/> tags to public members surfaced by commentchecker — resolves 5,847 of 5,869 issues (99.6%) across three /fixdocs passes.
102 lines
4.1 KiB
C#
102 lines
4.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Historian.Wonderware.Backend;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Host.Tests
|
|
{
|
|
[Trait("Category", "Unit")]
|
|
public sealed class HistorianClusterEndpointPickerTests
|
|
{
|
|
private static HistorianConfiguration Config(params string[] nodes) => new()
|
|
{
|
|
ServerName = "ignored",
|
|
ServerNames = nodes.ToList(),
|
|
FailureCooldownSeconds = 60,
|
|
};
|
|
|
|
/// <summary>Verifies that a single-node configuration falls back to ServerName when ServerNames is empty.</summary>
|
|
[Fact]
|
|
public void Single_node_config_falls_back_to_ServerName_when_ServerNames_empty()
|
|
{
|
|
var cfg = new HistorianConfiguration { ServerName = "only-node", ServerNames = new() };
|
|
var p = new HistorianClusterEndpointPicker(cfg);
|
|
p.NodeCount.ShouldBe(1);
|
|
p.GetHealthyNodes().ShouldBe(new[] { "only-node" });
|
|
}
|
|
|
|
/// <summary>Verifies that a failed node enters cooldown and is skipped from the healthy nodes list.</summary>
|
|
[Fact]
|
|
public void Failed_node_enters_cooldown_and_is_skipped()
|
|
{
|
|
var now = new DateTime(2026, 4, 18, 10, 0, 0, DateTimeKind.Utc);
|
|
var p = new HistorianClusterEndpointPicker(Config("a", "b"), () => now);
|
|
|
|
p.MarkFailed("a", "boom");
|
|
p.GetHealthyNodes().ShouldBe(new[] { "b" });
|
|
}
|
|
|
|
/// <summary>Verifies that the cooldown period expires after the configured time window.</summary>
|
|
[Fact]
|
|
public void Cooldown_expires_after_configured_window()
|
|
{
|
|
var clock = new DateTime(2026, 4, 18, 10, 0, 0, DateTimeKind.Utc);
|
|
var p = new HistorianClusterEndpointPicker(Config("a", "b"), () => clock);
|
|
p.MarkFailed("a", "boom");
|
|
p.GetHealthyNodes().ShouldBe(new[] { "b" });
|
|
|
|
clock = clock.AddSeconds(61);
|
|
p.GetHealthyNodes().ShouldBe(new[] { "a", "b" });
|
|
}
|
|
|
|
/// <summary>Verifies that marking a node healthy immediately clears its cooldown.</summary>
|
|
[Fact]
|
|
public void MarkHealthy_immediately_clears_cooldown()
|
|
{
|
|
var now = new DateTime(2026, 4, 18, 10, 0, 0, DateTimeKind.Utc);
|
|
var p = new HistorianClusterEndpointPicker(Config("a"), () => now);
|
|
p.MarkFailed("a", "boom");
|
|
p.GetHealthyNodes().ShouldBeEmpty();
|
|
p.MarkHealthy("a");
|
|
p.GetHealthyNodes().ShouldBe(new[] { "a" });
|
|
}
|
|
|
|
/// <summary>Verifies that when all nodes are in cooldown, an empty healthy list is returned.</summary>
|
|
[Fact]
|
|
public void All_nodes_in_cooldown_returns_empty_healthy_list()
|
|
{
|
|
var now = new DateTime(2026, 4, 18, 10, 0, 0, DateTimeKind.Utc);
|
|
var p = new HistorianClusterEndpointPicker(Config("a", "b"), () => now);
|
|
p.MarkFailed("a", "x");
|
|
p.MarkFailed("b", "y");
|
|
p.GetHealthyNodes().ShouldBeEmpty();
|
|
p.NodeCount.ShouldBe(2);
|
|
}
|
|
|
|
/// <summary>Verifies that a snapshot reports failure count and the last error message.</summary>
|
|
[Fact]
|
|
public void Snapshot_reports_failure_count_and_last_error()
|
|
{
|
|
var now = new DateTime(2026, 4, 18, 10, 0, 0, DateTimeKind.Utc);
|
|
var p = new HistorianClusterEndpointPicker(Config("a"), () => now);
|
|
p.MarkFailed("a", "first");
|
|
p.MarkFailed("a", "second");
|
|
|
|
var snap = p.SnapshotNodeStates().Single();
|
|
snap.FailureCount.ShouldBe(2);
|
|
snap.LastError.ShouldBe("second");
|
|
snap.IsHealthy.ShouldBeFalse();
|
|
snap.CooldownUntil.ShouldNotBeNull();
|
|
}
|
|
|
|
/// <summary>Verifies that duplicate hostnames are deduplicated case-insensitively.</summary>
|
|
[Fact]
|
|
public void Duplicate_hostnames_are_deduplicated_case_insensitively()
|
|
{
|
|
var p = new HistorianClusterEndpointPicker(Config("NodeA", "nodea", "NodeB"));
|
|
p.NodeCount.ShouldBe(2);
|
|
}
|
|
}
|
|
}
|