test(galaxy): #865 review round 7 - pin the superseded-pump fault filter

Adds an escalated-stream-fault test seam and a test: the live pump's fault
escalates (positive controls before and after), a superseded pump's late
fault after a reopen does not; the absence is asserted only once both
pumps' callbacks are known to have run (HasEnded). Verified to fail with
the filter disabled. The filter's comment now says the identity check does
the work and warns about a future session bump while Healthy.

Claude-Session: https://claude.ai/code/session_01GT67AD99zQQqpLCVm3p7xk
This commit is contained in:
Joseph Doherty
2026-11-11 13:20:49 -05:00
parent 13cc7b8353
commit 59d33ab938
2 changed files with 56 additions and 3 deletions
@@ -116,6 +116,12 @@ public sealed class ProbeInitialValueTests
}
}
/// <summary>Fault the currently attached stream (the gateway dropping it).</summary>
public void FaultAttachedStream(Exception cause)
{
lock (_gate) _attached.ShouldNotBeNull("a stream must be attached").Writer.TryComplete(cause);
}
public string[] CallsSnapshot()
{
lock (_gate) return [.. Calls];
@@ -349,6 +355,45 @@ public sealed class ProbeInitialValueTests
"a replay must not report success over a dead event stream");
}
/// <summary>
/// #865 review: a stream fault is escalated only from the LIVE pump. A fault from a pump superseded
/// by a reopen (its session is no longer current) is ignored — it would fail a good replay — while
/// the live pump's faults (before the reopen, and the replay's new pump after it) still escalate.
/// </summary>
[Fact]
public async Task Only_the_live_pumps_stream_faults_are_escalated()
{
var sub = new GatewayLikeSubscriber();
await using var driver = new GalaxyDriver("drv", Opts(), hierarchySource: null, subscriber: sub)
{
RecreateOverrideForTests = _ => Task.CompletedTask,
};
await driver.InitializeAsync("{}", CancellationToken.None);
await driver.SubscribeAsync(["Tank01.Level"], TimeSpan.Zero, CancellationToken.None); // pump 1
// Positive control: the live pump's fault escalates.
sub.FaultAttachedStream(new IOException("drop 1"));
await TestWait.UntilAsync(() => driver.EscalatedStreamFaultsForTests == 1, "the live pump's fault must escalate");
// Recover onto pump 2 (the replay restarts the faulted pump), then reopen: pump 2 is now superseded.
await driver.InvokeReplayForTestAsync(CancellationToken.None);
var pump2 = driver.EventPumpInstanceForTests.ShouldNotBeNull();
await driver.InvokeReopenForTestAsync(CancellationToken.None);
sub.FaultAttachedStream(new IOException("late fault from the superseded pump"));
await TestWait.UntilAsync(() => ((EventPump)pump2).HasEnded, "the superseded pump's stream must have faulted");
// Positive control after the absence: the replay's new pump faults and that DOES escalate — so the
// count can only be 2 if the superseded pump's fault was ignored.
await driver.InvokeReplayForTestAsync(CancellationToken.None);
var pump3 = (EventPump)driver.EventPumpInstanceForTests.ShouldNotBeNull();
pump3.ShouldNotBeSameAs(pump2);
sub.FaultAttachedStream(new IOException("drop 3"));
// HasEnded is set only after the fault callback ran, so once both pumps have ended every escalation
// that will ever happen has happened.
await TestWait.UntilAsync(() => pump3.HasEnded, "the new live pump's stream must have faulted");
driver.EscalatedStreamFaultsForTests.ShouldBe(2, "the new live pump's fault escalates; the superseded pump's did not");
}
/// <summary>
/// A probe sync on a driver whose pump was never started (no platform source, e.g. the
/// DiscoverAsync path) still starts it before advising — the watcher's pre-subscribe hook, not just