Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/OpcUaApplicationHostQuotaTests.cs
T
Joseph Doherty e42e666a1d fix(alarms): #937 review r2 — deadline/poison refusals unsent, Call size quota, expired asks skip the engine, mutation-counter revert guard
M1: a scripted method whose request deadline leaves < the dispatch floor, or that
follows an unanswered scripted method in the same Call, is refused BadTimeout in
its handler (unsent, unapplied); OpcUa:Quotas:MaxNodesPerMethodCall = 1000.
M2: ExecuteAlarmCommand carries the asker's deadline; an expired ask skips the
engine and is not remembered (the broadcast copy applies).
L1: revert guarded by a per-condition mutation counter; raw severity restored.
L5 + nits: docs, stale comment. SDK check: no Part 9 handler calls our delegate
before its own validation.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-11-28 12:47:08 -05:00

76 lines
2.9 KiB
C#

using Opc.Ua;
using Shouldly;
using Xunit;
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests;
/// <summary>Review 01 P6 — the SDK request and transport quotas are configurable (<c>OpcUa:Quotas:*</c>) and
/// default to exactly what used to be hard-coded.</summary>
public sealed class OpcUaApplicationHostQuotaTests
{
[Fact]
public void Default_request_quotas_are_the_former_hard_coded_values()
{
var config = new ServerConfiguration();
OpcUaApplicationHost.ApplyRequestQuotas(config, new OpcUaQuotaOptions());
config.MinRequestThreadCount.ShouldBe(5);
config.MaxRequestThreadCount.ShouldBe(100);
config.MaxQueuedRequestCount.ShouldBe(200);
config.OperationLimits.MaxNodesPerMethodCall.ShouldBe(1000u, "#937: a Call is bounded (the SDK default 0 is unlimited)");
}
[Fact]
public void Configured_request_quotas_are_applied()
{
var config = new ServerConfiguration();
OpcUaApplicationHost.ApplyRequestQuotas(config, new OpcUaQuotaOptions
{
MinRequestThreadCount = 8, MaxRequestThreadCount = 250, MaxQueuedRequestCount = 1000,
});
config.MinRequestThreadCount.ShouldBe(8);
config.MaxRequestThreadCount.ShouldBe(250);
config.MaxQueuedRequestCount.ShouldBe(1000);
}
[Fact]
public void Unset_transport_quotas_keep_the_sdk_defaults()
{
var sdkDefault = new TransportQuotas();
var built = OpcUaApplicationHost.BuildTransportQuotas(new OpcUaQuotaOptions());
built.OperationTimeout.ShouldBe(sdkDefault.OperationTimeout);
built.MaxStringLength.ShouldBe(sdkDefault.MaxStringLength);
built.MaxByteStringLength.ShouldBe(sdkDefault.MaxByteStringLength);
built.MaxArrayLength.ShouldBe(sdkDefault.MaxArrayLength);
built.MaxMessageSize.ShouldBe(sdkDefault.MaxMessageSize);
built.MaxBufferSize.ShouldBe(sdkDefault.MaxBufferSize);
built.ChannelLifetime.ShouldBe(sdkDefault.ChannelLifetime);
built.SecurityTokenLifetime.ShouldBe(sdkDefault.SecurityTokenLifetime);
}
[Fact]
public void Configured_transport_quotas_replace_only_what_is_set()
{
var sdkDefault = new TransportQuotas();
var built = OpcUaApplicationHost.BuildTransportQuotas(new OpcUaQuotaOptions
{
MaxMessageSize = 8 * 1024 * 1024, OperationTimeoutMs = 45_000, MaxArrayLength = 1_000_000,
});
built.MaxMessageSize.ShouldBe(8 * 1024 * 1024);
built.OperationTimeout.ShouldBe(45_000);
built.MaxArrayLength.ShouldBe(1_000_000);
built.MaxStringLength.ShouldBe(sdkDefault.MaxStringLength);
built.ChannelLifetime.ShouldBe(sdkDefault.ChannelLifetime);
}
[Fact]
public void History_read_batch_cap_default_scales_with_the_machine()
{
OtOpcUaNodeManager.DefaultMaxConcurrentHistoryReadBatches
.ShouldBe(Math.Clamp(Environment.ProcessorCount * 2, 4, 16));
}
}