fix(dashboard): close three low hub/page races (mxaccessgw#174)
D11: BrowsePage search CTS is cancelled+disposed exactly once under a lock. D12: the hub refreshes the cached health status before seeding a new connection. D13: DashboardEventBroadcaster gains DisposeAsync that awaits the pumps (bounded). Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -71,6 +71,29 @@ public sealed class DashboardEventBroadcasterTests
|
||||
Assert.Equal(1, hubContext.SendCount);
|
||||
}
|
||||
|
||||
/// <summary>DisposeAsync awaits the hub pumps so queued sends finish before it returns (R21-D13).</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task DisposeAsync_AwaitsPumpDrain()
|
||||
{
|
||||
CapturingHubContext hubContext = new();
|
||||
EventsHubViewerRegistry viewers = new();
|
||||
viewers.AddViewer("conn-1", "session-1");
|
||||
DashboardEventBroadcaster broadcaster = Create(hubContext, showTagValues: false, viewers);
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
broadcaster.Publish("session-1", BuildEventWithValue());
|
||||
}
|
||||
|
||||
await broadcaster.DisposeAsync();
|
||||
|
||||
// Every queued event was drained before DisposeAsync returned: nothing is left
|
||||
// in flight on a pump task past shutdown.
|
||||
Assert.Equal(20, hubContext.SendCount);
|
||||
Assert.Equal(0, broadcaster.ActiveHubPumpCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A hub viewer that cannot keep up costs a bounded queue, not an unbounded pile of
|
||||
/// pending sends: while one send is stuck, further events drop oldest-first at the
|
||||
|
||||
@@ -68,6 +68,23 @@ public sealed class DashboardSnapshotServiceTests
|
||||
Assert.Equal(1, health.CheckCount);
|
||||
}
|
||||
|
||||
/// <summary>RefreshGatewayStatusAsync updates the cached status without a watch tick (R21-D12).</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task RefreshGatewayStatusAsync_UpdatesCachedStatusWithoutWatching()
|
||||
{
|
||||
using GatewayMetrics metrics = new();
|
||||
StubHealthCheckService health = new(HealthStatus.Degraded);
|
||||
DashboardSnapshotService service = CreateService(new SessionRegistry(), metrics, healthCheckService: health);
|
||||
|
||||
Assert.NotEqual(HealthStatus.Degraded.ToString(), service.GetSnapshot().GatewayStatus);
|
||||
|
||||
await service.RefreshGatewayStatusAsync(CancellationToken.None);
|
||||
|
||||
Assert.Equal(HealthStatus.Degraded.ToString(), service.GetSnapshot().GatewayStatus);
|
||||
Assert.Equal(1, health.CheckCount);
|
||||
}
|
||||
|
||||
/// <summary>A health evaluation that throws is reported as Unknown, never as Healthy.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user