Files
ScadaBridge/tests/ZB.MOM.WW.ScadaBridge.Host.Tests/SiteKestrelSetupTests.cs
T
Joseph Doherty 513fa1aa16 docs(tests): fix CommentChecker findings across tests/ — 13,392 → 0 (repo-wide scan clean)
Comment/XML-doc changes only:
- add summaries to ~10k test methods, fixtures, fakes and helpers
  (+ <param> on theories, <returns> on async Task methods,
  <inheritdoc/> on interface implementations the checker can resolve)
- strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N,
  #NN, Component-0NN) from comments, keeping the explanatory text;
  reword false positives in comments only
- real docs on fakes implementing BCL/library interfaces
  (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime)
- reword the last 5 src/ false positives (CWE-1236, failures-1,
  year-0001, M365)

Only non-comment edits: four one-line nested classes split across lines
so members can carry docs. Build 0 errors / 0 warnings.
2026-10-07 15:05:49 -04:00

59 lines
3.0 KiB
C#

using Microsoft.AspNetCore.Server.Kestrel.Core;
using ZB.MOM.WW.ScadaBridge.Host;
namespace ZB.MOM.WW.ScadaBridge.Host.Tests;
/// <summary>
/// The site node's Kestrel configuration, asserted against the code that actually ships (the other
/// Host startup tests re-declare their own <c>ConfigureKestrel</c> lambda, which can never catch a
/// regression in <c>Program.cs</c>'s).
/// </summary>
public class SiteKestrelSetupTests
{
/// <summary>Verifies that the site listener enables HTTP/2 keepalive pings.</summary>
[Fact]
public void SiteListener_EnablesHttp2Keepalive()
{
// Kestrel's default KeepAlivePingDelay is TimeSpan.MaxValue —
// no server-initiated pings — so a half-open HTTP/2 connection is never detected on a
// stream that is legitimately silent. The LocalDb sync stream is exactly that: with the
// dialling node crashed or partitioned, this node's handler stays parked on a dead stream
// holding the single-stream guard, refusing the reconnect that would heal the pair.
var options = new KestrelServerOptions();
SiteKestrelSetup.Configure(options, grpcPort: 8083, metricsPort: 8084);
Assert.NotEqual(TimeSpan.MaxValue, options.Limits.Http2.KeepAlivePingDelay);
Assert.Equal(SiteKestrelSetup.Http2KeepAlivePingDelay, options.Limits.Http2.KeepAlivePingDelay);
Assert.Equal(SiteKestrelSetup.Http2KeepAlivePingTimeout, options.Limits.Http2.KeepAlivePingTimeout);
// Detection has to be quick enough to matter, and a ping must not be its own timeout.
Assert.True(SiteKestrelSetup.Http2KeepAlivePingTimeout < SiteKestrelSetup.Http2KeepAlivePingDelay);
Assert.True(
SiteKestrelSetup.Http2KeepAlivePingDelay + SiteKestrelSetup.Http2KeepAlivePingTimeout
<= TimeSpan.FromMinutes(2));
}
/// <summary>Verifies that the site listener keeps the gRPC port HTTP/2-only and the metrics port HTTP/1.1-capable.</summary>
[Fact]
public void SiteListener_KeepsGrpcHttp2Only_AndMetricsHttp1Capable()
{
// The keepalive change must not disturb the protocol split: h2c-only on the gRPC port so
// Grpc.AspNetCore can serve it without TLS ALPN, HTTP/1.1-capable on the metrics port so a
// standard Prometheus scraper can reach /metrics.
var options = new KestrelServerOptions();
SiteKestrelSetup.Configure(options, grpcPort: 8083, metricsPort: 8084);
var endpoints = options.GetType()
.GetProperty("CodeBackedListenOptions", System.Reflection.BindingFlags.Instance
| System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)!
.GetValue(options) as System.Collections.IEnumerable;
Assert.NotNull(endpoints);
var protocols = endpoints!.Cast<ListenOptions>().Select(o => o.Protocols).ToList();
Assert.Equal(2, protocols.Count);
Assert.Equal(HttpProtocols.Http2, protocols[0]);
Assert.Equal(HttpProtocols.Http1AndHttp2, protocols[1]);
}
}