10b898305f
S-1: replace the hand-maintained 5-project unit-tests matrix (which silently dropped Client's 388 tests, Analyzers' 31, and every driver + most Core suite) with ONE whole-solution leg — dotnet test ZB.MOM.WW.OtOpcUa.slnx --filter "Category!=E2E&Category!=LiveIntegration". Self-maintaining: a new *.Tests project is covered automatically, matching CLAUDE.md's own guidance. S-2: emit trx + add scripts/ci/assert-not-all-skipped.sh, a fail-on-skip gate that turns 'green CI == everything skipped' into a red build. Wired strict (MIN_EXECUTED=1) on the unit leg; report-only (MIN_EXECUTED=0) on the fixtureless integration leg so its skip tally is VISIBLE without a false red — with a documented follow-up to start the one public-image fixture (opc-plc) as a service and flip it strict. S-4 (paired): the newly-CI'd Client.CLI.Tests had fixed-sleep startup races (await Task.Delay(100/150) before cancelling a background command) that would flake under CI load. Added SubscribeInvoked / SubscribeAlarmsInvoked readiness signals (TaskCompletionSource) to FakeOpcUaClientService and replaced the 11 sleeps across AlarmsCommandTests / SubscribeCommandTests / EventHandlerLifecycleTests with a deterministic await-the-signal (10s timeout guard). Verified: workflow YAML parses; skip-gate proven locally on a real trx (executed=31 => OK), a synthetic all-skipped trx (executed=0 => exit 1 with diagnostic), report-only mode (never fails), multi-file sum, and missing-file (exit 2); Client.CLI.Tests 104/104 green after the deflake. (CI job execution itself is verifiable only on push — nothing pushed.)
156 lines
5.4 KiB
C#
156 lines
5.4 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Client.CLI.Commands;
|
|
using ZB.MOM.WW.OtOpcUa.Client.CLI.Tests.Fakes;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Client.CLI.Tests;
|
|
|
|
public class AlarmsCommandTests
|
|
{
|
|
/// <summary>Verifies that Execute subscribes to alarms.</summary>
|
|
[Fact]
|
|
public async Task Execute_SubscribesToAlarms()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new AlarmsCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840",
|
|
Interval = 2000
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
|
|
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
|
|
|
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
|
console.RequestCancellation();
|
|
await task;
|
|
|
|
fakeService.SubscribeAlarmsCalls.Count.ShouldBe(1);
|
|
fakeService.SubscribeAlarmsCalls[0].IntervalMs.ShouldBe(2000);
|
|
fakeService.SubscribeAlarmsCalls[0].SourceNodeId.ShouldBeNull();
|
|
}
|
|
|
|
/// <summary>Verifies that Execute with node passes source node ID.</summary>
|
|
[Fact]
|
|
public async Task Execute_WithNode_PassesSourceNodeId()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new AlarmsCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840",
|
|
NodeId = "ns=2;s=AlarmSource"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
|
|
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
|
|
|
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
|
console.RequestCancellation();
|
|
await task;
|
|
|
|
fakeService.SubscribeAlarmsCalls.Count.ShouldBe(1);
|
|
fakeService.SubscribeAlarmsCalls[0].SourceNodeId.ShouldNotBeNull();
|
|
fakeService.SubscribeAlarmsCalls[0].SourceNodeId!.Identifier.ShouldBe("AlarmSource");
|
|
}
|
|
|
|
/// <summary>Verifies that Execute with refresh requests condition refresh.</summary>
|
|
[Fact]
|
|
public async Task Execute_WithRefresh_RequestsConditionRefresh()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new AlarmsCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840",
|
|
Refresh = true
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
|
|
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
|
|
|
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
|
console.RequestCancellation();
|
|
await task;
|
|
|
|
fakeService.RequestConditionRefreshCalled.ShouldBeTrue();
|
|
var output = TestConsoleHelper.GetOutput(console);
|
|
output.ShouldContain("Condition refresh requested.");
|
|
}
|
|
|
|
/// <summary>Verifies that refresh failure prints error.</summary>
|
|
[Fact]
|
|
public async Task Execute_RefreshFailure_PrintsError()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService
|
|
{
|
|
ConditionRefreshException = new NotSupportedException("Not supported")
|
|
};
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new AlarmsCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840",
|
|
Refresh = true
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
|
|
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
|
|
|
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
|
console.RequestCancellation();
|
|
await task;
|
|
|
|
var output = TestConsoleHelper.GetOutput(console);
|
|
output.ShouldContain("Condition refresh not supported:");
|
|
}
|
|
|
|
/// <summary>Verifies that Execute unsubscribes on cancellation.</summary>
|
|
[Fact]
|
|
public async Task Execute_UnsubscribesOnCancellation()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new AlarmsCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
|
|
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
|
|
|
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
|
console.RequestCancellation();
|
|
await task;
|
|
|
|
fakeService.UnsubscribeAlarmsCalled.ShouldBeTrue();
|
|
}
|
|
|
|
/// <summary>Verifies that Execute disconnects in finally block.</summary>
|
|
[Fact]
|
|
public async Task Execute_DisconnectsInFinally()
|
|
{
|
|
var fakeService = new FakeOpcUaClientService();
|
|
var factory = new FakeOpcUaClientServiceFactory(fakeService);
|
|
var command = new AlarmsCommand(factory)
|
|
{
|
|
Url = "opc.tcp://localhost:4840"
|
|
};
|
|
|
|
using var console = TestConsoleHelper.CreateConsole();
|
|
|
|
var task = Task.Run(async () => { await command.ExecuteAsync(console); });
|
|
|
|
await fakeService.SubscribeAlarmsInvoked.WaitAsync(TimeSpan.FromSeconds(10));
|
|
console.RequestCancellation();
|
|
await task;
|
|
|
|
fakeService.DisconnectCalled.ShouldBeTrue();
|
|
fakeService.DisposeCalled.ShouldBeTrue();
|
|
}
|
|
} |