fix(ablegacy): stamp health from the injectable Clock; drop the redundant per-project TreatWarningsAsErrors (lmxopcua#768)
AbLegacyDriver stamped LastSuccessfulRead (init, read, write), the read's sample timestamps and host-state change times from raw DateTime.UtcNow; only the backoff path read the injectable Clock. All of them now read Clock(), so NativePcccBridgeStatusHealthTests drives a manual clock (init at T0, read at T1) and asserts LastSuccessfulRead == T1 exactly instead of spin-waiting for the wall clock to pass the init stamp (#767). Without the driver change the 6 tests fail (init stamp is wall-clock, not T0). Directory.Build.props sets TreatWarningsAsErrors for every project since #766, so the 75 per-csproj copies (64 src + 11 tests) are removed and the props comment says it is now the only place. tools/mem-probe keeps its explicit opt-out. Release build: 0 warnings, 0 errors; a planted CS0168 still fails the build in a src project and in a test project that used to carry its own copy. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Cluster.Tests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Commons.Tests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
+26
-21
@@ -45,20 +45,17 @@ public sealed class NativePcccBridgeStatusHealthTests
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// InitializeAsync stamps <c>LastSuccessfulRead</c> with <c>DateTime.UtcNow</c> and the read stamps its own
|
||||
/// <c>UtcNow</c> microseconds later; on a coarse/identical clock reading the two are equal, so an "advanced"
|
||||
/// assertion (<c>ShouldNotBe(before)</c>) failed ~70% of runs (lmxopcua#767). Spin until the clock has strictly
|
||||
/// passed the init stamp so any later stamp is provably newer. The assertion itself is unchanged.
|
||||
/// A manual clock the driver stamps health from (lmxopcua#768). Init stamps <see cref="InitTime"/>; each test
|
||||
/// moves it to <see cref="ReadTime"/> before reading, so an "advanced" <c>LastSuccessfulRead</c> is provably
|
||||
/// the read's stamp (it used to be <c>DateTime.UtcNow</c> twice microseconds apart, equal ~70% of runs on a
|
||||
/// coarse clock, lmxopcua#767).
|
||||
/// </summary>
|
||||
private static void WaitUntilClockPast(DateTime? stamp)
|
||||
{
|
||||
if (stamp is null) return;
|
||||
var spin = new SpinWait();
|
||||
while (DateTime.UtcNow <= stamp.Value) spin.SpinOnce();
|
||||
}
|
||||
private static readonly DateTime InitTime = new(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
private static readonly DateTime ReadTime = InitTime.AddSeconds(1);
|
||||
|
||||
#pragma warning disable OTOPCUA0001 // the driver is called directly to pin its OWN classification (no resilience wrap)
|
||||
private static async Task<AbLegacyDriver> DriverAsync(FakeEipServer server)
|
||||
private static async Task<AbLegacyDriver> DriverAsync(FakeEipServer server, Func<DateTime> clock)
|
||||
{
|
||||
var host = $"ab://127.0.0.1:{server.Port}/1,0";
|
||||
var driver = new AbLegacyDriver(new AbLegacyDriverOptions
|
||||
@@ -67,7 +64,10 @@ public sealed class NativePcccBridgeStatusHealthTests
|
||||
RawTags = AbLegacyRawTags.Entries([new AbLegacyTagDefinition("T", host, "N7:0", AbLegacyDataType.Int)]),
|
||||
Timeout = TimeSpan.FromSeconds(5),
|
||||
Probe = new AbLegacyProbeOptions { Enabled = false },
|
||||
}, "drv-pccc-bridge", new NativeAbLegacyTagFactory(new DeviceSessionPool()));
|
||||
}, "drv-pccc-bridge", new NativeAbLegacyTagFactory(new DeviceSessionPool()))
|
||||
{
|
||||
Clock = clock,
|
||||
};
|
||||
await driver.InitializeAsync("{}", TestContext.Current.CancellationToken);
|
||||
return driver;
|
||||
}
|
||||
@@ -78,8 +78,11 @@ public sealed class NativePcccBridgeStatusHealthTests
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
await using var server = StsServer(0x30);
|
||||
var driver = await DriverAsync(server);
|
||||
var now = InitTime;
|
||||
var driver = await DriverAsync(server, () => now);
|
||||
var before = driver.GetHealth().LastSuccessfulRead;
|
||||
before.ShouldBe(InitTime);
|
||||
now = ReadTime;
|
||||
|
||||
var result = (await driver.ReadAsync(["T"], ct)).Single();
|
||||
|
||||
@@ -97,17 +100,18 @@ public sealed class NativePcccBridgeStatusHealthTests
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
await using var server = StsServer(0x60);
|
||||
var driver = await DriverAsync(server);
|
||||
var now = InitTime;
|
||||
var driver = await DriverAsync(server, () => now);
|
||||
var before = driver.GetHealth().LastSuccessfulRead;
|
||||
WaitUntilClockPast(before);
|
||||
before.ShouldBe(InitTime);
|
||||
now = ReadTime;
|
||||
|
||||
var result = (await driver.ReadAsync(["T"], ct)).Single();
|
||||
|
||||
result.StatusCode.ShouldBe(AbOpcUaStatusMap.BadNotWritable);
|
||||
var health = driver.GetHealth();
|
||||
health.State.ShouldBe(DriverState.Healthy);
|
||||
health.LastSuccessfulRead.ShouldNotBeNull();
|
||||
health.LastSuccessfulRead.ShouldNotBe(before);
|
||||
health.LastSuccessfulRead.ShouldBe(ReadTime);
|
||||
await driver.ShutdownAsync(ct);
|
||||
server.HandlerErrors.ShouldBeEmpty();
|
||||
}
|
||||
@@ -128,17 +132,18 @@ public sealed class NativePcccBridgeStatusHealthTests
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
await using var server = general == 0 ? StsServer(0x10) : CipEnvelopeServer(general);
|
||||
var driver = await DriverAsync(server);
|
||||
var now = InitTime;
|
||||
var driver = await DriverAsync(server, () => now);
|
||||
var before = driver.GetHealth().LastSuccessfulRead;
|
||||
WaitUntilClockPast(before);
|
||||
before.ShouldBe(InitTime);
|
||||
now = ReadTime;
|
||||
|
||||
var result = (await driver.ReadAsync(["T"], ct)).Single();
|
||||
|
||||
result.StatusCode.ShouldBe(AbLegacyStatusMapper.BadNotSupported);
|
||||
var health = driver.GetHealth();
|
||||
health.State.ShouldBe(DriverState.Healthy);
|
||||
health.LastSuccessfulRead.ShouldNotBeNull();
|
||||
health.LastSuccessfulRead.ShouldNotBe(before);
|
||||
health.LastSuccessfulRead.ShouldBe(ReadTime);
|
||||
await driver.ShutdownAsync(ct);
|
||||
server.HandlerErrors.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
-1
@@ -27,7 +27,6 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.AdminUI.Tests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
-1
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.ControlPlane.Tests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
-1
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Host.IntegrationTests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Host.Tests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
-1
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- OTOPCUA0001 (#595): OpcUaClientDriverWireTests call driver capabilities directly at the wire level on
|
||||
|
||||
-1
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Runtime.Tests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<RootNamespace>ZB.MOM.WW.OtOpcUa.Security.Tests</RootNamespace>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user