487859bff0
Doc/XML-comment drift + small adherence fixes across 17 modules. Highlights: - Host-017: site CoordinatedShutdown ordering — SiteStreamGrpcServer gains CancelAllStreams() (refuse new streams, cancel active), wired into Program.cs site branch via ApplicationStopping. - InboundAPI-021: ParentExecutionId now travels on RouteToGet/SetAttributes symmetric with RouteToCallRequest; RouteHelper stamps from _parentExecutionId. - ClusterInfra-012: ClusterOptionsValidator now requires both seed nodes. - Comm-018: SiteCommunicationActor.HeartbeatMessage.IsActive derived from cluster leader check (was hardcoded true). - DM-020: reconciliation audit row attributes the current user, not prior deployer. - SEL-019: EventLogPurgeService early-exits on standby via active-node check. - Plus comment/XML-doc accuracy fixes across AuditLog, ConfigurationDatabase, NotificationOutbox, SiteRuntime, SiteCallAudit; doc refreshes for Component- Commons / -ManagementService / -CLI / -ExternalSystemGateway / -HealthMonitoring / -Transport / -ConfigurationDatabase; CD-023 index-name doc alignment. 11 new regression tests (RouteHelper x4, SiteStreamGrpcServer x2, ClusterOptionsValidator x1, SiteCommunicationActor x1, DeploymentService x1, EventLogPurgeService x3). Build clean (0 warnings); InboundAPI/Communication/ Host suites all green. README regenerated: 112 open (was 136).
149 lines
4.9 KiB
C#
149 lines
4.9 KiB
C#
using Microsoft.Extensions.Options;
|
|
|
|
namespace ScadaLink.ClusterInfrastructure.Tests;
|
|
|
|
/// <summary>
|
|
/// CI-004: Tests that <see cref="ClusterOptionsValidator"/> rejects the
|
|
/// catastrophic misconfigurations the design doc warns against — a
|
|
/// <c>MinNrOfMembers</c> other than 1, an unsupported split-brain strategy,
|
|
/// empty seed nodes, and timings where the heartbeat is not below the
|
|
/// failure-detection threshold.
|
|
/// </summary>
|
|
public class ClusterOptionsValidatorTests
|
|
{
|
|
private static ClusterOptions ValidOptions() => new()
|
|
{
|
|
SeedNodes = new List<string> { "akka.tcp://scadalink@node1:8081", "akka.tcp://scadalink@node2:8081" },
|
|
SplitBrainResolverStrategy = "keep-oldest",
|
|
StableAfter = TimeSpan.FromSeconds(15),
|
|
HeartbeatInterval = TimeSpan.FromSeconds(2),
|
|
FailureDetectionThreshold = TimeSpan.FromSeconds(10),
|
|
MinNrOfMembers = 1,
|
|
DownIfAlone = true
|
|
};
|
|
|
|
[Fact]
|
|
public void DefaultOptions_AreValid()
|
|
{
|
|
var result = new ClusterOptionsValidator().Validate(null, ValidOptions());
|
|
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void MinNrOfMembers_NotOne_FailsValidation()
|
|
{
|
|
var options = ValidOptions();
|
|
options.MinNrOfMembers = 2;
|
|
|
|
var result = new ClusterOptionsValidator().Validate(null, options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("MinNrOfMembers", result.FailureMessage);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("keep-majority")]
|
|
[InlineData("static-quorum")]
|
|
[InlineData("nonsense")]
|
|
public void UnsupportedSplitBrainStrategy_FailsValidation(string strategy)
|
|
{
|
|
var options = ValidOptions();
|
|
options.SplitBrainResolverStrategy = strategy;
|
|
|
|
var result = new ClusterOptionsValidator().Validate(null, options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("SplitBrainResolverStrategy", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptySeedNodes_FailsValidation()
|
|
{
|
|
var options = ValidOptions();
|
|
options.SeedNodes = new List<string>();
|
|
|
|
var result = new ClusterOptionsValidator().Validate(null, options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("SeedNodes", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void SingleSeedNode_FailsValidation()
|
|
{
|
|
// CI-012: design doc says "both nodes are seed nodes" — a single-seed
|
|
// configuration defeats the no-startup-ordering-dependency guarantee and
|
|
// must be rejected by the contract owner's validator, not just by the
|
|
// Host's startup validator.
|
|
var options = ValidOptions();
|
|
options.SeedNodes = new List<string> { "akka.tcp://scadalink@node1:8081" };
|
|
|
|
var result = new ClusterOptionsValidator().Validate(null, options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("SeedNodes", result.FailureMessage);
|
|
Assert.Contains("2", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void HeartbeatNotBelowFailureThreshold_FailsValidation()
|
|
{
|
|
var options = ValidOptions();
|
|
options.HeartbeatInterval = TimeSpan.FromSeconds(10);
|
|
options.FailureDetectionThreshold = TimeSpan.FromSeconds(10);
|
|
|
|
var result = new ClusterOptionsValidator().Validate(null, options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("HeartbeatInterval", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void NonPositiveStableAfter_FailsValidation()
|
|
{
|
|
var options = ValidOptions();
|
|
options.StableAfter = TimeSpan.Zero;
|
|
|
|
var result = new ClusterOptionsValidator().Validate(null, options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("StableAfter", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void DownIfAloneFalse_FailsValidation()
|
|
{
|
|
var options = ValidOptions();
|
|
options.DownIfAlone = false;
|
|
|
|
var result = new ClusterOptionsValidator().Validate(null, options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("DownIfAlone", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_AccumulatesAllFailures()
|
|
{
|
|
var options = new ClusterOptions
|
|
{
|
|
SeedNodes = new List<string>(),
|
|
SplitBrainResolverStrategy = "keep-majority",
|
|
MinNrOfMembers = 2,
|
|
StableAfter = TimeSpan.Zero,
|
|
HeartbeatInterval = TimeSpan.FromSeconds(20),
|
|
FailureDetectionThreshold = TimeSpan.FromSeconds(10)
|
|
};
|
|
|
|
var result = new ClusterOptionsValidator().Validate(null, options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("SeedNodes", result.FailureMessage);
|
|
Assert.Contains("SplitBrainResolverStrategy", result.FailureMessage);
|
|
Assert.Contains("MinNrOfMembers", result.FailureMessage);
|
|
Assert.Contains("StableAfter", result.FailureMessage);
|
|
Assert.Contains("HeartbeatInterval", result.FailureMessage);
|
|
}
|
|
}
|