test(adminui): review fixes — locked-snapshot assert, stable fake health, InitializeCount property
This commit is contained in:
@@ -172,7 +172,7 @@ public sealed class DriverReconnectE2eTests
|
|||||||
List<DriverHealthChanged> snapshot;
|
List<DriverHealthChanged> snapshot;
|
||||||
lock (captureLock) snapshot = captured.Where(c => c.DriverInstanceId == DriverId).ToList();
|
lock (captureLock) snapshot = captured.Where(c => c.DriverInstanceId == DriverId).ToList();
|
||||||
|
|
||||||
HasReconnectThenHealthy(captured).ShouldBeTrue(
|
HasReconnectThenHealthy(snapshot).ShouldBeTrue(
|
||||||
"Expected a Reconnecting push followed by a later Healthy push for the deployed driver. " +
|
"Expected a Reconnecting push followed by a later Healthy push for the deployed driver. " +
|
||||||
$"States seen: [{string.Join(", ", snapshot.Select(c => c.State))}]");
|
$"States seen: [{string.Join(", ", snapshot.Select(c => c.State))}]");
|
||||||
|
|
||||||
@@ -254,6 +254,8 @@ public sealed class DriverReconnectE2eTests
|
|||||||
await db.SaveChangesAsync(Ct);
|
await db.SaveChangesAsync(Ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Polls <paramref name="condition"/> every 100 ms until it returns true or
|
||||||
|
/// <paramref name="timeout"/> elapses (then throws <see cref="TimeoutException"/>).</summary>
|
||||||
private static async Task WaitForAsync(Func<Task<bool>> condition, TimeSpan timeout)
|
private static async Task WaitForAsync(Func<Task<bool>> condition, TimeSpan timeout)
|
||||||
{
|
{
|
||||||
var deadline = DateTime.UtcNow + timeout;
|
var deadline = DateTime.UtcNow + timeout;
|
||||||
|
|||||||
+8
-5
@@ -96,13 +96,16 @@ public sealed class FakeReconnectDriver : IDriver
|
|||||||
/// <summary>Timestamp of the most recent successful initialize; surfaced as the last successful read.</summary>
|
/// <summary>Timestamp of the most recent successful initialize; surfaced as the last successful read.</summary>
|
||||||
private DateTime _lastSuccess = DateTime.UtcNow;
|
private DateTime _lastSuccess = DateTime.UtcNow;
|
||||||
|
|
||||||
|
/// <summary>Backing field for <see cref="InitializeCount"/>; mutated via <see cref="Interlocked"/>.</summary>
|
||||||
|
private int _initializeCount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Number of times <see cref="InitializeAsync"/> has been invoked. Read by the test to prove a
|
/// Number of times <see cref="InitializeAsync"/> has been invoked. Read by the test to prove a
|
||||||
/// reconnect genuinely re-initialised the driver through the full cluster path (≥ 2 means the
|
/// reconnect genuinely re-initialised the driver through the full cluster path (≥ 2 means the
|
||||||
/// initial connect plus at least one reconnect retry). Mutated via <see cref="Interlocked"/> since
|
/// initial connect plus at least one reconnect retry). The actor's retry path runs on a thread-pool
|
||||||
/// the actor's retry path runs on a thread-pool thread.
|
/// thread, so the increment is <see cref="Interlocked"/> and the read is <see cref="Volatile"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int InitializeCount;
|
public int InitializeCount => Volatile.Read(ref _initializeCount);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Marks the driver as having lost its connection so the next <see cref="GetHealth"/> poll reports
|
/// Marks the driver as having lost its connection so the next <see cref="GetHealth"/> poll reports
|
||||||
@@ -123,7 +126,7 @@ public sealed class FakeReconnectDriver : IDriver
|
|||||||
/// <returns>A completed task — initialization always succeeds.</returns>
|
/// <returns>A completed task — initialization always succeeds.</returns>
|
||||||
public Task InitializeAsync(string driverConfigJson, CancellationToken cancellationToken)
|
public Task InitializeAsync(string driverConfigJson, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
Interlocked.Increment(ref InitializeCount);
|
Interlocked.Increment(ref _initializeCount);
|
||||||
_lastSuccess = DateTime.UtcNow;
|
_lastSuccess = DateTime.UtcNow;
|
||||||
_reconnecting = false;
|
_reconnecting = false;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
@@ -151,7 +154,7 @@ public sealed class FakeReconnectDriver : IDriver
|
|||||||
/// <returns>A <see cref="DriverHealth"/> reflecting the controllable connection state.</returns>
|
/// <returns>A <see cref="DriverHealth"/> reflecting the controllable connection state.</returns>
|
||||||
public DriverHealth GetHealth() => _reconnecting
|
public DriverHealth GetHealth() => _reconnecting
|
||||||
? new DriverHealth(DriverState.Reconnecting, _lastSuccess, null)
|
? new DriverHealth(DriverState.Reconnecting, _lastSuccess, null)
|
||||||
: new DriverHealth(DriverState.Healthy, DateTime.UtcNow, null);
|
: new DriverHealth(DriverState.Healthy, _lastSuccess, null);
|
||||||
|
|
||||||
/// <summary>Returns a zero memory footprint (the fake holds no driver-attributable caches).</summary>
|
/// <summary>Returns a zero memory footprint (the fake holds no driver-attributable caches).</summary>
|
||||||
/// <returns>Always <c>0</c>.</returns>
|
/// <returns>Always <c>0</c>.</returns>
|
||||||
|
|||||||
Reference in New Issue
Block a user