Group all 69 projects into category subfolders under src/ and tests/ so the Rider Solution Explorer mirrors the module structure. Folders: Core, Server, Drivers (with a nested Driver CLIs subfolder), Client, Tooling. - Move every project folder on disk with git mv (history preserved as renames). - Recompute relative paths in 57 .csproj files: cross-category ProjectReferences, the lib/ HintPath+None refs in Driver.Historian.Wonderware, and the external mxaccessgw refs in Driver.Galaxy and its test project. - Rebuild ZB.MOM.WW.OtOpcUa.slnx with nested solution folders. - Re-prefix project paths in functional scripts (e2e, compliance, smoke SQL, integration, install). Build green (0 errors); unit tests pass. Docs left for a separate pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
93 lines
3.1 KiB
C#
93 lines
3.1 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Server.Redundancy;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Server.Tests;
|
|
|
|
[Trait("Category", "Unit")]
|
|
public sealed class RecoveryStateManagerTests
|
|
{
|
|
private static readonly DateTime T0 = new(2026, 4, 19, 12, 0, 0, DateTimeKind.Utc);
|
|
|
|
private sealed class FakeTimeProvider : TimeProvider
|
|
{
|
|
public DateTime Utc { get; set; } = T0;
|
|
public override DateTimeOffset GetUtcNow() => new(Utc, TimeSpan.Zero);
|
|
}
|
|
|
|
[Fact]
|
|
public void NeverFaulted_DwellIsAutomaticallyMet()
|
|
{
|
|
var mgr = new RecoveryStateManager();
|
|
mgr.IsDwellMet().ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void AfterFault_Only_IsDwellMet_Returns_True_ButCallerDoesntQueryDuringFaulted()
|
|
{
|
|
// Documented semantics: IsDwellMet is only consulted when selfHealthy=true (i.e. the
|
|
// node has recovered into Healthy). During Faulted the coordinator short-circuits on
|
|
// the self-health check and never calls IsDwellMet. So returning true here is harmless;
|
|
// the test captures the intent so a future "return false during Faulted" tweak has to
|
|
// deliberately change this test first.
|
|
var mgr = new RecoveryStateManager();
|
|
mgr.MarkFaulted();
|
|
mgr.IsDwellMet().ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void AfterRecovery_NoWitness_DwellNotMet_EvenAfterElapsed()
|
|
{
|
|
var clock = new FakeTimeProvider();
|
|
var mgr = new RecoveryStateManager(dwellTime: TimeSpan.FromSeconds(60), timeProvider: clock);
|
|
mgr.MarkFaulted();
|
|
mgr.MarkRecovered();
|
|
clock.Utc = T0.AddSeconds(120);
|
|
|
|
mgr.IsDwellMet().ShouldBeFalse("dwell elapsed but no publish witness — must NOT escape Recovering band");
|
|
}
|
|
|
|
[Fact]
|
|
public void AfterRecovery_WitnessButTooSoon_DwellNotMet()
|
|
{
|
|
var clock = new FakeTimeProvider();
|
|
var mgr = new RecoveryStateManager(dwellTime: TimeSpan.FromSeconds(60), timeProvider: clock);
|
|
mgr.MarkFaulted();
|
|
mgr.MarkRecovered();
|
|
mgr.RecordPublishWitness();
|
|
clock.Utc = T0.AddSeconds(30);
|
|
|
|
mgr.IsDwellMet().ShouldBeFalse("witness ok but dwell 30s < 60s");
|
|
}
|
|
|
|
[Fact]
|
|
public void AfterRecovery_Witness_And_DwellElapsed_Met()
|
|
{
|
|
var clock = new FakeTimeProvider();
|
|
var mgr = new RecoveryStateManager(dwellTime: TimeSpan.FromSeconds(60), timeProvider: clock);
|
|
mgr.MarkFaulted();
|
|
mgr.MarkRecovered();
|
|
mgr.RecordPublishWitness();
|
|
clock.Utc = T0.AddSeconds(61);
|
|
|
|
mgr.IsDwellMet().ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ReFault_ResetsWitness_AndDwellClock()
|
|
{
|
|
var clock = new FakeTimeProvider();
|
|
var mgr = new RecoveryStateManager(dwellTime: TimeSpan.FromSeconds(60), timeProvider: clock);
|
|
mgr.MarkFaulted();
|
|
mgr.MarkRecovered();
|
|
mgr.RecordPublishWitness();
|
|
clock.Utc = T0.AddSeconds(61);
|
|
mgr.IsDwellMet().ShouldBeTrue();
|
|
|
|
mgr.MarkFaulted();
|
|
mgr.MarkRecovered();
|
|
clock.Utc = T0.AddSeconds(100); // re-entered Recovering, no new witness
|
|
mgr.IsDwellMet().ShouldBeFalse("new recovery needs its own witness");
|
|
}
|
|
}
|