Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.ClusterInfrastructure.Tests/ClusterOptionsTests.cs
T
Joseph Doherty efade2eab0 feat(cluster)!: leader-auto-down is the shipped default downing strategy (#116)
SplitBrainResolverStrategy now defaults to leader-auto-down (the in-repo
LeaderAutoDowningProvider, #106, with the #132 shut-out restart on). auto-down and
keep-oldest stay supported. Drilled on the docker rig, docker-env2 and the QA pair
(central + site, kill and stop-and-hold) before the flip.

- ClusterOptions default + validator/HOCON comments updated.
- Shipped Host appsettings.Central/Site.json and every docker/ and docker-env2/
  node appsettings now say leader-auto-down. The leader-auto-down overlays are
  kept as no-ops (drill records reference them); new docker-compose.auto-down.yml
  overlays keep Akka AutoDowning available for comparison drills.
- Tests: default asserts leader-auto-down; new HOCON test for an unset strategy;
  TwoNodeClusterFixture defaults to the production posture.
- Docs: CLAUDE.md, Component-ClusterInfrastructure, components/Host + Cluster,
  README, failover procedures, Traefik, docker + env2 READMEs; register row 70 closed.

No deploy needed: DEV, QA and both rigs set the key explicitly.

Claude-Session: https://claude.ai/code/session_01GT67AFKC45MBz1wPZnVbX8
2026-11-15 19:57:45 -05:00

86 lines
3.9 KiB
C#

namespace ZB.MOM.WW.ScadaBridge.ClusterInfrastructure.Tests;
/// <summary>
/// Tests for ClusterOptions default values and property setters.
/// </summary>
public class ClusterOptionsTests
{
/// <summary>Verifies that a new options instance carries the expected default values.</summary>
[Fact]
public void DefaultValues_AreCorrect()
{
var options = new ClusterOptions();
// 'leader-auto-down' is the default since 2026-11-15 (ScadaBridge#116): the in-repo port
// of the availability-first 'auto-down' posture (decision 2026-07-21), without Akka's
// deprecated AutoDowning provider. A crash of either node fails over to the survivor.
Assert.Equal("leader-auto-down", options.SplitBrainResolverStrategy);
Assert.True(options.LeaderAutoDown.RestartWhenShutOut);
Assert.Equal(TimeSpan.FromSeconds(15), options.StableAfter);
Assert.Equal(TimeSpan.FromSeconds(2), options.HeartbeatInterval);
Assert.Equal(TimeSpan.FromSeconds(10), options.FailureDetectionThreshold);
Assert.Equal(1, options.MinNrOfMembers);
Assert.True(options.DownIfAlone);
}
/// <summary>Verifies that the down-if-alone setting can be changed.</summary>
[Fact]
public void DownIfAlone_CanBeSet()
{
var options = new ClusterOptions { DownIfAlone = false };
Assert.False(options.DownIfAlone);
}
/// <summary>Verifies that the seed node list defaults to an empty list.</summary>
[Fact]
public void SeedNodes_DefaultsToEmptyList()
{
var options = new ClusterOptions();
Assert.NotNull(options.SeedNodes);
Assert.Empty(options.SeedNodes);
}
// The SectionName constant was deleted — the previous test
// `SectionName_IsTheExpectedAppSettingsSection` is removed alongside it.
// The Host's SiteServiceRegistration / StartupValidator continue to
// reference the `"ScadaBridge:Cluster"` literal directly; reinstating the
// constant should happen when those Host binding sites can be updated in
// the same change.
/// <summary>Verifies that the options properties accept custom values.</summary>
[Fact]
public void Properties_CanBeSetToCustomValues()
{
// This test exercises the POCO property setters only —
// `SplitBrainResolverStrategy = "keep-majority"` and `MinNrOfMembers = 2`
// are values the design doc explicitly forbids in production
// (`keep-majority` causes total shutdown on a two-node partition;
// `MinNrOfMembers = 2` blocks the cluster singleton after failover).
// The POCO accepts any value by design; rejection lives in
// `ClusterOptionsValidator` and is covered by
// `ClusterOptionsValidatorTests.UnsupportedSplitBrainStrategy_FailsValidation`
// and `ClusterOptionsValidatorTests.MinNrOfMembers_NotOne_FailsValidation`.
// Do NOT read these values as endorsed runtime configuration.
var options = new ClusterOptions
{
SeedNodes = new List<string> { "akka.tcp://system@node1:2551", "akka.tcp://system@node2:2551" },
SplitBrainResolverStrategy = "keep-majority",
StableAfter = TimeSpan.FromSeconds(30),
HeartbeatInterval = TimeSpan.FromSeconds(5),
FailureDetectionThreshold = TimeSpan.FromSeconds(20),
MinNrOfMembers = 2
};
Assert.Equal(2, options.SeedNodes.Count);
Assert.Contains("akka.tcp://system@node1:2551", options.SeedNodes);
Assert.Contains("akka.tcp://system@node2:2551", options.SeedNodes);
Assert.Equal("keep-majority", options.SplitBrainResolverStrategy);
Assert.Equal(TimeSpan.FromSeconds(30), options.StableAfter);
Assert.Equal(TimeSpan.FromSeconds(5), options.HeartbeatInterval);
Assert.Equal(TimeSpan.FromSeconds(20), options.FailureDetectionThreshold);
Assert.Equal(2, options.MinNrOfMembers);
}
}