fix(galaxy): unify IsConnected with _connected guard; AttachForTests marks connected (review)

This commit is contained in:
Joseph Doherty
2026-06-11 09:16:51 -04:00
parent 43b96441a5
commit 565b77e6cf
2 changed files with 36 additions and 2 deletions
@@ -98,9 +98,38 @@ public sealed class GalaxyMxSessionReconnectTests
await Should.ThrowAsync<InvalidOperationException>(
async () => await session.ConnectAsync(null!, CancellationToken.None));
openCount.ShouldBe(1);
session.IsConnected.ShouldBeFalse(); // _connected must NOT be latched by the failed attempt.
// The failed first attempt must not have latched _connected — the retry reaches the body.
await session.ConnectAsync(null!, CancellationToken.None);
openCount.ShouldBe(2);
}
/// <summary>
/// <see cref="GalaxyMxSession.IsConnected"/> tracks the <c>_connected</c> guard across the
/// full lifecycle: false when fresh, true after connect, still true after a recreate, and
/// false again after dispose.
/// </summary>
[Fact]
public async Task IsConnected_reflects_connect_recreate_and_dispose()
{
var session = NewSession();
var openCount = 0;
session.OpenAndRegisterOverrideForTests = _ =>
{
openCount++;
return Task.CompletedTask;
};
session.IsConnected.ShouldBeFalse();
await session.ConnectAsync(null!, CancellationToken.None);
session.IsConnected.ShouldBeTrue();
await session.RecreateAsync(null!, CancellationToken.None);
session.IsConnected.ShouldBeTrue();
await session.DisposeAsync();
session.IsConnected.ShouldBeFalse();
}
}