fix(overview): P3 review fixes 003-005 - no redirects on probes, per-target publish so a hung instance cannot stale the rest, probe docs (scadaproj#48)
Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -401,6 +401,55 @@ public class OverviewPollerServiceTests
|
||||
Assert.All(snapshot.AllInstances, i => Assert.Equal(InstanceStatus.Up, i.Status));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Sweep_HungInstanceDoesNotHoldUpResultsOrLaterSweepsForTheOthers()
|
||||
{
|
||||
// Overview-004: a hung instance (long timeout override) used to gate the whole sweep, so
|
||||
// every other instance went Stale between polls. The fast instance must publish as soon as
|
||||
// it answers, and a later sweep must not wait for the hung one.
|
||||
var handler = new RoutingHandler()
|
||||
.Json("http://fast:8080/health/ready", HttpStatusCode.OK, HealthBody.Ready("Healthy"))
|
||||
.Json("http://slow:8080/health/ready", HttpStatusCode.OK, HealthBody.Ready("Healthy"));
|
||||
var options = Registry(App("App", Node("fast", "http://fast:8080"), Node("slow", "http://slow:8080")));
|
||||
var time = new FakeTimeProvider(Start);
|
||||
var (poller, store) = Build(options, new HangingHandler(handler, "slow"), time);
|
||||
|
||||
var first = poller.SweepAsync();
|
||||
|
||||
// The fast result is published while the slow probe is still hanging.
|
||||
await WaitUntilAsync(() => store.Current.AllInstances.Any(i => i.Instance == "fast" && i.Status == InstanceStatus.Up));
|
||||
Assert.False(first.IsCompleted);
|
||||
|
||||
time.Advance(TimeSpan.FromSeconds(11));
|
||||
var second = await poller.SweepAsync().WaitAsync(TimeSpan.FromSeconds(10));
|
||||
|
||||
Assert.False(first.IsCompleted);
|
||||
Assert.Equal(2, ReadyProbes(handler, "fast"));
|
||||
Assert.Equal(InstanceStatus.Up, second.AllInstances.Single(i => i.Instance == "fast").Status);
|
||||
}
|
||||
|
||||
private static async Task WaitUntilAsync(Func<bool> condition)
|
||||
{
|
||||
var deadline = DateTime.UtcNow.AddSeconds(10);
|
||||
while (!condition())
|
||||
{
|
||||
Assert.True(DateTime.UtcNow < deadline, "condition not met in time");
|
||||
await Task.Delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class HangingHandler(RoutingHandler inner, string hangingHost) : HttpMessageHandler
|
||||
{
|
||||
protected override async Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.RequestUri!.Host == hangingHost)
|
||||
await Task.Delay(Timeout.Infinite, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return await inner.HandleAsync(request).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Sweep_UnregisteredInstances_RenderAsPendingNotAsHealthy()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user