test(mtconnect): #661 make the reconnect-counter wait cancellable (no background spin after the watchdog)

Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
Joseph Doherty
2026-10-09 06:03:05 -04:00
parent 480b000f53
commit 31e2148a27
@@ -995,11 +995,13 @@ public sealed class MTConnectSubscribeTests
client.SampleCallCount.ShouldBe(3);
}
private static async Task WaitForReconnectAttemptsAboveAsync(MTConnectDriver driver, int floor)
private static async Task WaitForReconnectAttemptsAboveAsync(MTConnectDriver driver, int floor, CancellationToken ct)
{
using var watchdog = CancellationTokenSource.CreateLinkedTokenSource(ct);
watchdog.CancelAfter(Watchdog);
while (driver.ReconnectAttempts <= floor)
{
await Task.Delay(5).ConfigureAwait(false);
await Task.Delay(5, watchdog.Token).ConfigureAwait(false);
}
}
@@ -1027,7 +1029,7 @@ public sealed class MTConnectSubscribeTests
// call fails, and `early` may have been read late (already past the 6th call) under load,
// so a call-count barrier can observe the counter unchanged. The failure is sticky, so a
// working backoff keeps growing it; a frozen one never satisfies this within the watchdog.
await WaitForReconnectAttemptsAboveAsync(driver, early).WaitAsync(Watchdog, Ct);
await WaitForReconnectAttemptsAboveAsync(driver, early, Ct);
early.ShouldBeGreaterThanOrEqualTo(2);
driver.ReconnectAttempts.ShouldBeGreaterThan(early);
@@ -1081,7 +1083,7 @@ public sealed class MTConnectSubscribeTests
// call fails, and `early` may have been read late (already past the 6th call) under load,
// so a call-count barrier can observe the counter unchanged. The failure is sticky, so a
// working backoff keeps growing it; a frozen one never satisfies this within the watchdog.
await WaitForReconnectAttemptsAboveAsync(driver, early).WaitAsync(Watchdog, Ct);
await WaitForReconnectAttemptsAboveAsync(driver, early, Ct);
early.ShouldBeGreaterThanOrEqualTo(2);
driver.ReconnectAttempts.ShouldBeGreaterThan(early);