0658d244d0
- HistoryUpdate items with SourceTimestamp > now + ServerHistorian:HistoryUpdateMaxFutureSkew (default 1 day, <=0 disables) => BadOutOfRange in the node manager (every backend, never sent); clock injected via OtOpcUaNodeManager.Clock (host TimeProvider). - HistoryUpdate is Primary-only: off-Primary => BadInvalidState per node, after authorization, same IDriverPrimaryRoleSource verdict as the native-ack gate; HistoryRead ungated. - SqlServer: base schema requirement back to v1; SupportsModifiedTrail (v>=2). On v1 with AutoCreateSchema=false: writes/reads/events/retention work, modified reads + HistoryUpdate => BadHistoryOperationUnsupported with nothing sent, retention skips SampleModified, one Warning per boot. - QuestDB integration test pinning wall-clock TTL (far-future row evicts only partitions older than the TTL by the wall clock), with a positive control. - Docs: Historian.md, Configuration.md, security.md, CLAUDE.md (incl. QuestDB retry duplicates, #674.4 anonymous-readable trail with ACL off, #674.5 not implemented). Co-Authored-By: Claude <noreply@anthropic.com>
139 lines
5.6 KiB
C#
139 lines
5.6 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Runtime.Historian;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Historian;
|
|
|
|
/// <summary>
|
|
/// Covers the gateway-shaped <see cref="ServerHistorianOptions.Validate"/> warnings: a disabled or
|
|
/// correctly-configured historian is silent; an enabled one with a blank <c>Endpoint</c> or blank
|
|
/// <c>ApiKey</c> surfaces an operator-facing warning (carrying no secret value text).
|
|
/// </summary>
|
|
public sealed class ServerHistorianOptionsTests
|
|
{
|
|
[Fact]
|
|
public void Disabled_yields_no_warnings()
|
|
=> Assert.Empty(new ServerHistorianOptions { Enabled = false }.Validate());
|
|
|
|
[Fact]
|
|
public void Enabled_without_endpoint_warns()
|
|
{
|
|
var w = new ServerHistorianOptions { Enabled = true, Endpoint = "", ApiKey = "histgw_x_y" }.Validate();
|
|
Assert.Contains(w, m => m.Contains("Endpoint"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Enabled_with_malformed_endpoint_warns()
|
|
{
|
|
// archreview 06/S-11 warning parity: a non-empty but unparseable / non-absolute Endpoint warns
|
|
// too, so the Runtime-side registration logs describe malformed endpoints (not just empty ones),
|
|
// keeping this surface consistent with the Host's fail-fast ServerHistorianOptionsValidator.
|
|
var w = new ServerHistorianOptions { Enabled = true, Endpoint = "not a uri", ApiKey = "histgw_x_y" }.Validate();
|
|
Assert.Contains(w, m => m.Contains("Endpoint"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Enabled_without_apikey_warns()
|
|
{
|
|
var w = new ServerHistorianOptions { Enabled = true, Endpoint = "https://h:5222", ApiKey = "" }.Validate();
|
|
Assert.Contains(w, m => m.Contains("ApiKey"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Valid_config_is_clean()
|
|
=> Assert.Empty(new ServerHistorianOptions { Enabled = true, Endpoint = "https://h:5222", ApiKey = "histgw_x_y" }.Validate());
|
|
|
|
[Fact]
|
|
public void Enabled_with_nonpositive_MaxTieClusterOverfetch_warns()
|
|
{
|
|
var w = new ServerHistorianOptions
|
|
{ Enabled = true, Endpoint = "https://h:5222", ApiKey = "histgw_x_y", MaxTieClusterOverfetch = 0 }
|
|
.Validate();
|
|
Assert.Contains(w, m => m.Contains("MaxTieClusterOverfetch"));
|
|
}
|
|
|
|
// ── S3 HistoryRead concurrency knobs (arch-review 03/S3) ────────────────────────────────────
|
|
|
|
[Fact]
|
|
public void HistoryRead_knob_defaults()
|
|
{
|
|
var o = new ServerHistorianOptions();
|
|
Assert.Equal(4, o.HistoryReadBatchParallelism);
|
|
Assert.Equal(16, o.MaxConcurrentHistoryReadBatches);
|
|
Assert.Equal(TimeSpan.FromSeconds(60), o.HistoryReadDeadline);
|
|
}
|
|
|
|
[Fact]
|
|
public void Enabled_with_nonpositive_HistoryReadBatchParallelism_warns()
|
|
{
|
|
var w = new ServerHistorianOptions
|
|
{ Enabled = true, Endpoint = "https://h:5222", ApiKey = "histgw_x_y", HistoryReadBatchParallelism = 0 }
|
|
.Validate();
|
|
Assert.Contains(w, m => m.Contains("HistoryReadBatchParallelism"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Enabled_with_nonpositive_MaxConcurrentHistoryReadBatches_warns()
|
|
{
|
|
var w = new ServerHistorianOptions
|
|
{ Enabled = true, Endpoint = "https://h:5222", ApiKey = "histgw_x_y", MaxConcurrentHistoryReadBatches = 0 }
|
|
.Validate();
|
|
Assert.Contains(w, m => m.Contains("MaxConcurrentHistoryReadBatches"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Enabled_with_nonpositive_HistoryReadDeadline_warns()
|
|
{
|
|
var w = new ServerHistorianOptions
|
|
{ Enabled = true, Endpoint = "https://h:5222", ApiKey = "histgw_x_y", HistoryReadDeadline = TimeSpan.Zero }
|
|
.Validate();
|
|
Assert.Contains(w, m => m.Contains("HistoryReadDeadline"));
|
|
}
|
|
|
|
[Fact]
|
|
public void MaxTimeWeightedRawRows_defaults_to_one_million_and_warns_when_nonpositive()
|
|
{
|
|
Assert.Equal(1_000_000, new ServerHistorianOptions().MaxTimeWeightedRawRows);
|
|
var w = new ServerHistorianOptions
|
|
{ Enabled = true, Endpoint = "https://h:5222", ApiKey = "histgw_x_y", MaxTimeWeightedRawRows = 0 }
|
|
.Validate();
|
|
Assert.Contains(w, m => m.Contains("MaxTimeWeightedRawRows"));
|
|
}
|
|
|
|
/// <summary>
|
|
/// #674: the HistoryUpdate future-skew bound defaults to one day and binds from configuration as a TimeSpan;
|
|
/// a non-positive value is a deliberate "disabled", not a misconfiguration, so it does not warn.
|
|
/// </summary>
|
|
[Fact]
|
|
public void HistoryUpdateMaxFutureSkew_defaults_to_one_day_binds_and_zero_is_silent()
|
|
{
|
|
Assert.Equal(TimeSpan.FromDays(1), new ServerHistorianOptions().HistoryUpdateMaxFutureSkew);
|
|
var bound = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ServerHistorian:HistoryUpdateMaxFutureSkew"] = "00:05:00",
|
|
})
|
|
.Build()
|
|
.GetSection(ServerHistorianOptions.SectionName)
|
|
.Get<ServerHistorianOptions>();
|
|
Assert.Equal(TimeSpan.FromMinutes(5), bound!.HistoryUpdateMaxFutureSkew);
|
|
var w = new ServerHistorianOptions
|
|
{ Enabled = true, Endpoint = "https://h:5222", ApiKey = "histgw_x_y", HistoryUpdateMaxFutureSkew = TimeSpan.Zero }
|
|
.Validate();
|
|
Assert.Empty(w);
|
|
}
|
|
|
|
[Fact]
|
|
public void Disabled_with_nonpositive_HistoryRead_knobs_is_silent()
|
|
{
|
|
var w = new ServerHistorianOptions
|
|
{
|
|
Enabled = false,
|
|
HistoryReadBatchParallelism = 0,
|
|
MaxConcurrentHistoryReadBatches = 0,
|
|
HistoryReadDeadline = TimeSpan.Zero,
|
|
}.Validate();
|
|
Assert.Empty(w);
|
|
}
|
|
}
|