fix(historian-gateway): Dispose() delegates to DisposeAsync() + sync-dispose test

Addresses T7/T8/T11 code-review minors: route the sync dispose through DisposeAsync
so a double Dispose()+DisposeAsync() stays a no-op; cover the sync path.

Claude-Session: https://claude.ai/code/session_012SDSQ3AcaXqPcBtDESBRii
This commit is contained in:
Joseph Doherty
2026-06-26 16:54:23 -04:00
parent 718f1fdad2
commit 1d5fa8230e
2 changed files with 11 additions and 2 deletions
@@ -335,8 +335,8 @@ public sealed class GatewayHistorianDataSource : IHistorianDataSource, IAsyncDis
}
}
/// <summary>Disposes the underlying gateway client.</summary>
public void Dispose() => _client.DisposeAsync().AsTask().GetAwaiter().GetResult();
/// <summary>Disposes the underlying gateway client. Prefer <see cref="DisposeAsync"/>.</summary>
public void Dispose() => DisposeAsync().AsTask().GetAwaiter().GetResult();
/// <summary>Asynchronously disposes the underlying gateway client.</summary>
/// <returns>A task that completes when the client has been disposed.</returns>
@@ -69,6 +69,15 @@ public sealed class GatewayHistorianDataSourceTests
Assert.Equal(1, fake.DisposeCallCount);
}
[Fact]
public void Dispose_via_sync_path_disposes_client()
{
var fake = new FakeHistorianGatewayClient();
var ds = new GatewayHistorianDataSource(fake, NullLogger<GatewayHistorianDataSource>.Instance);
((IDisposable)ds).Dispose();
Assert.Equal(1, fake.DisposeCallCount);
}
// Ts(...) builds a Google.Protobuf.WellKnownTypes.Timestamp from UTC parts.
private static Timestamp Ts(int y, int mo, int d, int h, int mi, int s)
=> Timestamp.FromDateTime(new DateTime(y, mo, d, h, mi, s, DateTimeKind.Utc));