fix(GWC-33): unregister terminal worker queue gauge

This commit is contained in:
Joseph Doherty
2026-08-25 10:56:23 -04:00
parent f2090fe1b5
commit b0156c685e
2 changed files with 49 additions and 3 deletions
@@ -1147,6 +1147,41 @@ public sealed class WorkerClientTests
Assert.Equal(0, metrics.GetSnapshot().WorkerEventQueueDepth);
}
/// <summary>
/// GWC-33: a faulted client can remain retained for diagnostics, but its abandoned event
/// backlog must stop contributing to the gateway-wide queue-depth gauge as soon as the
/// client enters a terminal state rather than waiting for disposal.
/// </summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[Fact]
public async Task WorkerEventQueueDepthGauge_WhenClientFaults_StopsCountingRetainedClient()
{
using GatewayMetrics metrics = new();
await using PipePair pipePair = await PipePair.CreateAsync();
await using WorkerClient client = CreateClient(
pipePair,
new WorkerClientOptions
{
EventChannelCapacity = 4,
EventChannelFullModeTimeout = TimeSpan.FromMinutes(5),
HeartbeatGrace = TimeSpan.FromSeconds(30),
HeartbeatCheckInterval = TimeSpan.FromSeconds(30),
},
metrics: metrics);
await CompleteHandshakeAsync(client, pipePair);
await pipePair.WriteAsync(CreateEventEnvelope(sequence: 1, MxEventFamily.OnDataChange));
await WaitUntilAsync(
() => metrics.GetSnapshot().WorkerEventQueueDepth == 1,
TestTimeout);
await pipePair.WriteAsync(CreateWorkerFaultEnvelope("scripted retained-client fault"));
await WaitUntilAsync(() => client.State == WorkerClientState.Faulted, TestTimeout);
Assert.Equal(WorkerClientState.Faulted, client.State);
Assert.Equal(0, metrics.GetSnapshot().WorkerEventQueueDepth);
}
private static WorkerClient CreateClient(
PipePair pipePair,
WorkerClientOptions? options = null,