fix(overview): one bad health response no longer stops the dashboard host (scadaproj#29)
ZbHealthReportClient caught only HttpRequestException/OperationCanceledException, so an unknown Content-Type charset (InvalidOperationException from ReadAsStringAsync) escaped the probe, faulted Task.WhenAll and the poller BackgroundService, and StopHost took the dashboard down. - client: final catch-all returns an Unreachable result for that instance - poller: per-target Guarded probe + catch-and-log per sweep in ExecuteAsync - tests: unknown charset (both tiers), arbitrary handler exception, sweep with one bad instance, and the BackgroundService survival loop - code-reviews: Overview-001 Resolved; README regenerated Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
@@ -210,6 +210,38 @@ public class ZbHealthReportClientTests
|
||||
Assert.Null(result.StatusCode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task Probe_UnknownCharset_IsUnreachableNotThrown(bool bodyRequired)
|
||||
{
|
||||
// Overview-001 (scadaproj#29): ReadAsStringAsync throws InvalidOperationException for a
|
||||
// Content-Type charset it cannot map to an Encoding. That escaped ProbeAsync, faulted the
|
||||
// poller BackgroundService and the default StopHost policy took the whole dashboard down.
|
||||
var client = new ZbHealthReportClient(new HttpClient(new BogusCharsetHandler()));
|
||||
|
||||
var result = bodyRequired
|
||||
? await client.ProbeAsync("http://node/health/ready", ProbeTimeout)
|
||||
: await client.ProbeStatusAsync("http://node/health/active", ProbeTimeout);
|
||||
|
||||
Assert.False(result.Reachable);
|
||||
Assert.Equal(200, result.StatusCode);
|
||||
Assert.NotNull(result.Error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Probe_ArbitraryHandlerException_IsUnreachableNotThrown()
|
||||
{
|
||||
var client = new ZbHealthReportClient(
|
||||
new HttpClient(new ThrowingHandler(new InvalidOperationException("boom"))));
|
||||
|
||||
var result = await client.ProbeAsync("http://node/health/ready", ProbeTimeout);
|
||||
|
||||
Assert.False(result.Reachable);
|
||||
Assert.Null(result.StatusCode);
|
||||
Assert.Contains("boom", result.Error, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Probe_ReadyTierStillDemandsAParseableBody()
|
||||
{
|
||||
@@ -233,6 +265,18 @@ public class ZbHealthReportClientTests
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>A 200 whose Content-Type names a charset no Encoding maps to.</summary>
|
||||
internal sealed class BogusCharsetHandler : HttpMessageHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(
|
||||
HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
var content = new ByteArrayContent(Encoding.UTF8.GetBytes("""{"status":"Healthy","entries":{}}"""));
|
||||
content.Headers.TryAddWithoutValidation("Content-Type", "application/json; charset=bogus-xyz");
|
||||
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = content });
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ThrowingHandler(Exception exception) : HttpMessageHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(
|
||||
|
||||
Reference in New Issue
Block a user