68 lines
3.3 KiB
C#
68 lines
3.3 KiB
C#
using Opc.Ua;
|
|
using Opc.Ua.Server;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
using HistorianRead = ZB.MOM.WW.OtOpcUa.Core.Abstractions.HistoryReadResult;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests;
|
|
|
|
/// <summary>
|
|
/// #736 — assigning <see cref="OtOpcUaNodeManager.HistorianDataSource"/> re-syncs
|
|
/// <c>HistoryServerCapabilities/MaxReturnDataValues</c> (i=11273) to the source's
|
|
/// <see cref="IHistorianDataSource.MaxRawValuesPerRead"/>, read back the way a client would. The Null
|
|
/// source (the historian-disabled default) advertises Part 11's "no limit".
|
|
/// </summary>
|
|
public sealed class NodeManagerMaxReturnDataValuesSyncTests(BoundsServerFixture fx) : IClassFixture<BoundsServerFixture>
|
|
{
|
|
[Fact]
|
|
public async Task Setting_the_historian_source_advertises_its_raw_cap()
|
|
{
|
|
await fx.Gate.WaitAsync(TestContext.Current.CancellationToken);
|
|
try
|
|
{
|
|
fx.Nm.HistorianDataSource = new CappedSource(7_000);
|
|
(await ReadAdvertisedAsync()).ShouldBe(7_000u);
|
|
|
|
fx.Nm.HistorianDataSource = new CappedSource(250);
|
|
(await ReadAdvertisedAsync()).ShouldBe(250u);
|
|
|
|
fx.Nm.HistorianDataSource = null!; // the Null default: no cap
|
|
(await ReadAdvertisedAsync()).ShouldBe(0u);
|
|
}
|
|
finally
|
|
{
|
|
fx.Nm.HistorianDataSource = null!;
|
|
fx.Gate.Release();
|
|
}
|
|
}
|
|
|
|
private async Task<uint> ReadAdvertisedAsync()
|
|
{
|
|
var context = new OperationContext(new RequestHeader(), secureChannelContext: null, RequestType.Read, requestLifetime: RequestLifetime.None, identity: null);
|
|
var nodesToRead = new List<ReadValueId>
|
|
{
|
|
new ReadValueId { NodeId = VariableIds.HistoryServerCapabilities_MaxReturnDataValues, AttributeId = Attributes.Value },
|
|
};
|
|
var (values, _) = await fx.Nm.Server.NodeManager.ReadAsync(context, 0, TimestampsToReturn.Neither, nodesToRead, TestContext.Current.CancellationToken);
|
|
values.Count.ShouldBe(1);
|
|
StatusCode.IsGood(values[0].StatusCode).ShouldBeTrue(values[0].StatusCode.ToString());
|
|
return (uint)SdkValueBoundary.ToClr(values[0].WrappedValue)!;
|
|
}
|
|
|
|
private sealed class CappedSource(int cap) : IHistorianDataSource
|
|
{
|
|
public int MaxRawValuesPerRead => cap;
|
|
public Task<HistorianRead> ReadRawAsync(string r, DateTime s, DateTime e, uint m, CancellationToken ct) =>
|
|
NullHistorianDataSource.Instance.ReadRawAsync(r, s, e, m, ct);
|
|
public Task<HistorianRead> ReadProcessedAsync(string r, DateTime s, DateTime e, TimeSpan i, HistoryAggregateType a, CancellationToken ct) =>
|
|
NullHistorianDataSource.Instance.ReadProcessedAsync(r, s, e, i, a, ct);
|
|
public Task<HistorianRead> ReadAtTimeAsync(string r, IReadOnlyList<DateTime> t, CancellationToken ct) =>
|
|
NullHistorianDataSource.Instance.ReadAtTimeAsync(r, t, ct);
|
|
public Task<HistoricalEventsResult> ReadEventsAsync(string? n, DateTime s, DateTime e, int m, CancellationToken ct) =>
|
|
NullHistorianDataSource.Instance.ReadEventsAsync(n, s, e, m, ct);
|
|
public HistorianHealthSnapshot GetHealthSnapshot() => NullHistorianDataSource.Instance.GetHealthSnapshot();
|
|
public void Dispose() { }
|
|
}
|
|
}
|