test(ablegacy): make the LastSuccessfulRead-advanced assertions deterministic by waiting for the clock to pass the init stamp (lmxopcua#767)

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 13:33:13 -05:00
parent b8202e1147
commit c29f98ffe0
@@ -44,6 +44,19 @@ public sealed class NativePcccBridgeStatusHealthTests
return server;
}
/// <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.
/// </summary>
private static void WaitUntilClockPast(DateTime? stamp)
{
if (stamp is null) return;
var spin = new SpinWait();
while (DateTime.UtcNow <= stamp.Value) spin.SpinOnce();
}
#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)
{
@@ -86,6 +99,7 @@ public sealed class NativePcccBridgeStatusHealthTests
await using var server = StsServer(0x60);
var driver = await DriverAsync(server);
var before = driver.GetHealth().LastSuccessfulRead;
WaitUntilClockPast(before);
var result = (await driver.ReadAsync(["T"], ct)).Single();
@@ -116,6 +130,7 @@ public sealed class NativePcccBridgeStatusHealthTests
await using var server = general == 0 ? StsServer(0x10) : CipEnvelopeServer(general);
var driver = await DriverAsync(server);
var before = driver.GetHealth().LastSuccessfulRead;
WaitUntilClockPast(before);
var result = (await driver.ReadAsync(["T"], ct)).Single();