Resolve Tests-027..031: flake root cause + coverage gaps

Tests-027  GatewayMetrics exposes its internal Meter; the
           StreamEvents_WhenEventIsWritten_RecordsSendDuration listener
           now filters by ReferenceEquals(instrument.Meter, metrics.Meter)
           instead of Meter.Name, so parallel tests with their own
           GatewayMetrics no longer cross-contaminate the families list.
Tests-028  FakeWorkerClient.Kill now captures LastKillReason;
           SessionManager.KillWorkerAsync tests pin the reason
           propagation end-to-end and cover the blank/null guard. The
           DashboardSessionAdminService kill test pins the literal
           dashboard-admin-kill reason.
Tests-029  Added CloseSessionAsync_BlankSessionId_ReturnsFailure to mirror
           the existing KillWorkerAsync blank-id coverage.
Tests-030  DeleteAsync_WhenStoreRefuses_ReportsFriendlyError renamed and
           extended to assert the dashboard-delete-key audit row with
           Details = not-found-or-active. Added
           DeleteAsync_BlankKeyId_ReturnsFailure.
Tests-031  DashboardSnapshotPublisher reconnect test now measures the
           gap from the first throw inside the fake (firstThrowAt) to
           secondSubscribeAt, isolating Task.Delay from StartAsync /
           scheduling overhead.

All resolved at 2026-05-24; 512/512 gateway tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-24 09:28:54 -04:00
parent 430187c28b
commit 6bae5ea3a3
7 changed files with 255 additions and 18 deletions
@@ -466,7 +466,12 @@ public sealed class SessionManagerTests
Assert.Equal(0, metrics.GetSnapshot().OpenSessions);
}
/// <summary>Verifies that killing a worker removes the session from the registry without calling shutdown.</summary>
/// <summary>
/// Verifies that killing a worker removes the session from the registry without calling shutdown.
/// Tests-028: also pins the <c>reason</c> argument propagating through
/// <c>SessionManager.KillWorkerAsync</c> → <c>session.KillWorker(reason)</c> →
/// <c>IWorkerClient.Kill(reason)</c>.
/// </summary>
[Fact]
public async Task KillWorkerAsync_KillsWorkerAndRemovesSession()
{
@@ -480,12 +485,54 @@ public sealed class SessionManagerTests
Assert.False(result.AlreadyClosed);
Assert.Equal(SessionState.Closed, result.FinalState);
Assert.Equal(1, workerClient.KillCount);
Assert.Equal("test-kill", workerClient.LastKillReason);
Assert.Equal(0, workerClient.ShutdownCount);
Assert.False(manager.TryGetSession(session.SessionId, out _));
Assert.Equal(1, metrics.GetSnapshot().SessionsClosed);
Assert.Equal(0, metrics.GetSnapshot().OpenSessions);
}
/// <summary>
/// Tests-028: <see cref="SessionManager.KillWorkerAsync"/> guards its <c>reason</c> argument with
/// <see cref="ArgumentException.ThrowIfNullOrWhiteSpace"/>. A blank or whitespace reason must throw
/// <see cref="ArgumentException"/> before any session lookup or worker call runs.
/// </summary>
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData("\t")]
public async Task KillWorkerAsync_WithBlankReason_ThrowsArgumentException(string blankReason)
{
FakeWorkerClient workerClient = new();
SessionManager manager = CreateManager(new FakeSessionWorkerClientFactory(workerClient));
GatewaySession session = await manager.OpenSessionAsync(CreateOpenRequest(), "client-1", CancellationToken.None);
await Assert.ThrowsAsync<ArgumentException>(
async () => await manager.KillWorkerAsync(session.SessionId, blankReason, CancellationToken.None));
Assert.Equal(0, workerClient.KillCount);
Assert.True(manager.TryGetSession(session.SessionId, out _));
}
/// <summary>
/// Tests-028: <see cref="ArgumentException.ThrowIfNullOrWhiteSpace"/> also rejects null.
/// <see cref="Theory"/> with <see cref="InlineDataAttribute"/> cannot carry <c>null</c> for a
/// non-nullable string parameter on .NET 10, so the null case is its own fact.
/// </summary>
[Fact]
public async Task KillWorkerAsync_WithNullReason_ThrowsArgumentNullException()
{
FakeWorkerClient workerClient = new();
SessionManager manager = CreateManager(new FakeSessionWorkerClientFactory(workerClient));
GatewaySession session = await manager.OpenSessionAsync(CreateOpenRequest(), "client-1", CancellationToken.None);
await Assert.ThrowsAsync<ArgumentNullException>(
async () => await manager.KillWorkerAsync(session.SessionId, null!, CancellationToken.None));
Assert.Equal(0, workerClient.KillCount);
Assert.True(manager.TryGetSession(session.SessionId, out _));
}
/// <summary>Verifies that killing the worker for an unknown session raises SessionNotFound.</summary>
[Fact]
public async Task KillWorkerAsync_WhenSessionMissing_ThrowsSessionNotFound()
@@ -827,6 +874,15 @@ public sealed class SessionManagerTests
/// <summary>Gets the number of times kill was called on the fake worker client.</summary>
public int KillCount { get; private set; }
/// <summary>
/// Gets the last reason argument observed by <see cref="Kill"/>. Tests-028:
/// pins the reason-string propagation through
/// <c>SessionManager.KillWorkerAsync</c> → <c>session.KillWorker(reason)</c> →
/// <c>IWorkerClient.Kill(reason)</c>. Without this, the chain could silently
/// drop or substitute the reason argument and existing tests would still pass.
/// </summary>
public string? LastKillReason { get; private set; }
/// <summary>Gets the number of times dispose was called on the fake worker client.</summary>
public int DisposeCount { get; private set; }
@@ -913,6 +969,7 @@ public sealed class SessionManagerTests
public void Kill(string reason)
{
KillCount++;
LastKillReason = reason;
if (KillException is not null)
{
throw KillException;