c4f97d0e87
Extend CommunicationOptionsValidator with eager bounds for the four T4 live-alarm-cache options (linger >= 0, reconcile > 0, seed concurrency 1..64, subscribers-per-site >= 1). Enforce the per-site viewer cap fail-safe in SiteAlarmLiveCacheService.Subscribe (reject excess viewers with a no-op disposable rather than growing the list or throwing into the Blazor render path). Surface two telemetry instruments on the existing ScadaBridgeTelemetry meter: an active-aggregator observable gauge and a reconnect counter, wired from the aggregator actor's PreStart/PostStop and its NodeA<->NodeB flip / reconcile-driven reopen. Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
90 lines
3.4 KiB
C#
90 lines
3.4 KiB
C#
using Microsoft.Extensions.Options;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
|
|
|
/// <summary>
|
|
/// Regression: <see cref="CommunicationOptions"/> timeouts feed per-pattern Ask
|
|
/// deadlines and gRPC keepalive/stream-lifetime settings; a zero/negative value
|
|
/// (or a non-positive <c>GrpcMaxConcurrentStreams</c>) must be rejected at startup
|
|
/// by an <see cref="IValidateOptions{TOptions}"/> with a clear, key-naming message
|
|
/// rather than surfacing at first Ask/gRPC use.
|
|
/// </summary>
|
|
public class CommunicationOptionsValidatorTests
|
|
{
|
|
private static ValidateOptionsResult Validate(CommunicationOptions options) =>
|
|
new CommunicationOptionsValidator().Validate(Options.DefaultName, options);
|
|
|
|
[Fact]
|
|
public void DefaultOptions_AreValid()
|
|
{
|
|
var result = Validate(new CommunicationOptions());
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroDeploymentTimeout_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { DeploymentTimeout = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("DeploymentTimeout", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void NonPositiveGrpcMaxConcurrentStreams_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { GrpcMaxConcurrentStreams = 0 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("GrpcMaxConcurrentStreams", result.FailureMessage);
|
|
}
|
|
|
|
// ── Aggregated live alarm cache options (plan #10, Task 6) ───────────────────
|
|
|
|
[Fact]
|
|
public void ZeroLiveAlarmCacheLinger_IsValid()
|
|
{
|
|
// Zero linger = stop the aggregator immediately when the last viewer leaves.
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheLinger = TimeSpan.Zero });
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void NegativeLiveAlarmCacheLinger_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheLinger = TimeSpan.FromSeconds(-1) });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheLinger", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroLiveAlarmCacheReconcileInterval_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheReconcileInterval = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheReconcileInterval", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroLiveAlarmCacheSeedConcurrency_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheSeedConcurrency = 0 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheSeedConcurrency", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExcessiveLiveAlarmCacheSeedConcurrency_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheSeedConcurrency = 65 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheSeedConcurrency", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroLiveAlarmCacheMaxSubscribersPerSite_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheMaxSubscribersPerSite = 0 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheMaxSubscribersPerSite", result.FailureMessage);
|
|
}
|
|
}
|