6c4d29902e
v2-ci / unit-tests (push) Has been cancelled
#899 — EnsureTags is an upsert, so binding a node to an existing AVEVA tag via historianTagname re-typed/re-described it on every add and host start. - TagConfig `historianReadOnly: true` (TagConfigIntent -> RawTagPlan.HistorianReadOnly): HistoryRead from an existing historian tag that OtOpcUa never provisions and never records into (AddressSpaceApplier.IsOwnedHistorizedValue gates both the EnsureTags hook and the recorder feed). Node-inert: surgical, not mirrored on UNS refs, in the RawTagPlan equality/hash. A non-bool value is the deploy error HistorianReadOnlyInvalid. AdminUI: CSV column HistorianReadOnly (strict), TagHistorizeConfig reads via the runtime parse. - ServerHistorian:ProvisionTags = CreateOrUpdate (default, unchanged) | CreateOnly (Gateway only: TagExistsAsync first, existing tags left alone, failed lookup not sent) | Off. Unknown value / CreateOnly on a SQL backend fail host start. - Default for an explicit historianTagname stays OWNED: overrides pin owned history across renames, a read-only default would silently stop provisioning + recording. #898 — the hook parsed Tag.DataType (an OPC UA name) as DriverDataType, so historized Float/Double/Byte/SByte tags were never provisioned. New shared HistorianDataTypeNames.TryResolve: Float->Float32, Double->Float64, Byte/SByte->Int16 (lossless, provisioned as Int2); unmapped names logged at Information. Gateway now skips Int64/UInt64 (HistorianGateway cannot create Int8/UInt8: lossless-cast-or-reject). UPGRADE: the first host start after this provisions (upserts) every existing historized Float/Double/Byte/SByte tag. Mark foreign-tag bindings historianReadOnly, or set ServerHistorian:ProvisionTags=CreateOnly/Off, before upgrading (docs/Historian.md). Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
494 lines
25 KiB
C#
494 lines
25 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests;
|
|
|
|
/// <summary>
|
|
/// T15 — verifies the non-blocking historian-provisioning hook in
|
|
/// <see cref="AddressSpaceApplier.Apply"/>. The hook fires AFTER the address-space work and
|
|
/// dispatches <see cref="IHistorianProvisioning.EnsureTagsAsync"/> fire-and-forget, so a slow or
|
|
/// throwing provisioner can never block or break a deploy on the OPC UA publish actor's pinned
|
|
/// thread.
|
|
/// </summary>
|
|
public sealed class AddressSpaceApplierProvisioningTests
|
|
{
|
|
/// <summary>Capturing <see cref="IHistorianProvisioning"/> double. Records the requests it was
|
|
/// handed and signals a <see cref="TaskCompletionSource"/> when invoked, so a test can await the
|
|
/// fire-and-forget dispatch deterministically (never poll/sleep). A <see cref="Throw"/> flag
|
|
/// simulates a synchronous provisioner fault.</summary>
|
|
private sealed class CapturingProvisioner : IHistorianProvisioning
|
|
{
|
|
private readonly TaskCompletionSource _called = new(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
|
|
/// <summary>Gets the requests the hook handed to <see cref="EnsureTagsAsync"/>.</summary>
|
|
public List<HistorianTagProvisionRequest> Seen { get; } = new();
|
|
|
|
/// <summary>When true, <see cref="EnsureTagsAsync"/> throws synchronously (a fault before any await).</summary>
|
|
public bool Throw { get; init; }
|
|
|
|
/// <summary>Completes once <see cref="EnsureTagsAsync"/> has been invoked.</summary>
|
|
public Task Called => _called.Task;
|
|
|
|
/// <inheritdoc />
|
|
public Task<HistorianProvisionResult> EnsureTagsAsync(
|
|
IReadOnlyList<HistorianTagProvisionRequest> requests, CancellationToken ct)
|
|
{
|
|
if (Throw)
|
|
{
|
|
_called.TrySetResult();
|
|
throw new InvalidOperationException("boom");
|
|
}
|
|
|
|
Seen.AddRange(requests);
|
|
_called.TrySetResult();
|
|
return Task.FromResult(new HistorianProvisionResult(requests.Count, requests.Count, 0, 0));
|
|
}
|
|
}
|
|
|
|
/// <summary>The hook provisions ONLY historized added tags, with the resolved historian name
|
|
/// (override when set, else the driver-side FullName).</summary>
|
|
[Fact]
|
|
public async Task Apply_provisions_only_historized_added_tags()
|
|
{
|
|
var prov = new CapturingProvisioner();
|
|
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance, prov);
|
|
|
|
// Leaf display name "Temp"; historian override "Pump1.Temp".
|
|
var plan = PlanWithAddedTags(
|
|
HistorizedTag(displayName: "Temp", historianName: "Pump1.Temp", dataType: "Float32"),
|
|
NonHistorizedTag(displayName: "Run", dataType: "Boolean"));
|
|
|
|
var outcome = applier.Apply(plan);
|
|
|
|
outcome.RebuildCalled.ShouldBeFalse(); // PureAdd — no rebuild; provisioning still fires
|
|
outcome.AddedNodes.ShouldBeGreaterThan(0);
|
|
|
|
// Fire-and-forget: await the capturing double's signal so the assertion is deterministic.
|
|
await prov.Called.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
|
prov.Seen.Count.ShouldBe(1);
|
|
prov.Seen[0].TagName.ShouldBe("Pump1.Temp"); // resolved historian name (override)
|
|
prov.Seen[0].DataType.ShouldBe(DriverDataType.Float32);
|
|
prov.Seen[0].Description.ShouldBe("Temp"); // leaf display name
|
|
}
|
|
|
|
/// <summary>A null/blank historian-name override resolves to the driver-side FullName — mirroring
|
|
/// the materialiser's resolution exactly.</summary>
|
|
[Fact]
|
|
public async Task Apply_resolves_historian_name_from_fullname_when_override_blank()
|
|
{
|
|
var prov = new CapturingProvisioner();
|
|
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance, prov);
|
|
|
|
// IsHistorized but no override → historian name falls back to FullName ("40001").
|
|
var plan = PlanWithAddedTags(
|
|
HistorizedTag(displayName: "Speed", historianName: null, dataType: "Int32", fullName: "40001"));
|
|
|
|
applier.Apply(plan);
|
|
|
|
await prov.Called.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
|
prov.Seen.Count.ShouldBe(1);
|
|
prov.Seen[0].TagName.ShouldBe("40001");
|
|
prov.Seen[0].DataType.ShouldBe(DriverDataType.Int32);
|
|
}
|
|
|
|
/// <summary>A synchronously-throwing provisioner must NOT block or break the publish: the
|
|
/// synchronous <see cref="AddressSpaceApplier.Apply"/> still completes its address-space work and
|
|
/// returns its normal outcome.</summary>
|
|
[Fact]
|
|
public void Provisioner_throw_does_not_block_publish()
|
|
{
|
|
var applier = new AddressSpaceApplier(
|
|
NullOpcUaAddressSpaceSink.Instance,
|
|
NullLogger<AddressSpaceApplier>.Instance,
|
|
new CapturingProvisioner { Throw = true });
|
|
|
|
var outcome = applier.Apply(PlanWithAddedTags(
|
|
HistorizedTag(displayName: "Temp", historianName: "Pump1.Temp", dataType: "Float32")));
|
|
|
|
outcome.RebuildCalled.ShouldBeFalse(); // PureAdd — no rebuild; Apply still completed + provisioned
|
|
}
|
|
|
|
/// <summary>The default ctor (no provisioner) binds the no-op <see cref="NullHistorianProvisioning"/>
|
|
/// and never faults a deploy — preserving every existing call site.</summary>
|
|
[Fact]
|
|
public void Default_ctor_uses_null_provisioning_and_does_not_throw()
|
|
{
|
|
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance);
|
|
|
|
var outcome = applier.Apply(PlanWithAddedTags(
|
|
HistorizedTag(displayName: "Temp", historianName: "Pump1.Temp", dataType: "Float32")));
|
|
|
|
outcome.RebuildCalled.ShouldBeFalse(); // PureAdd — no rebuild; default no-op provisioning still safe
|
|
outcome.AddedNodes.ShouldBeGreaterThan(0);
|
|
}
|
|
|
|
/// <summary>lmxopcua#898: Tag.DataType holds OPC UA built-in names (what the AdminUI writes). Float, Double, Byte and
|
|
/// SByte used to fail <c>Enum.TryParse<DriverDataType></c> and were silently never provisioned; they now resolve
|
|
/// (Float→Float32, Double→Float64, Byte/SByte→Int16, a lossless widening). The DriverDataType spelling still works,
|
|
/// and a name with no historian mapping (Guid) is skipped without faulting the hook.</summary>
|
|
[Fact]
|
|
public async Task Apply_provisions_opc_ua_type_names_and_skips_unmapped_ones()
|
|
{
|
|
var prov = new CapturingProvisioner();
|
|
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance, prov);
|
|
|
|
var plan = PlanWithAddedTags(
|
|
HistorizedTag(displayName: "F", historianName: "P.F", dataType: "Float"),
|
|
HistorizedTag(displayName: "D", historianName: "P.D", dataType: "Double"),
|
|
HistorizedTag(displayName: "B", historianName: "P.B", dataType: "Byte"),
|
|
HistorizedTag(displayName: "S", historianName: "P.S", dataType: "SByte"),
|
|
HistorizedTag(displayName: "F32", historianName: "P.F32", dataType: "Float32"),
|
|
HistorizedTag(displayName: "G", historianName: "P.G", dataType: "Guid"));
|
|
|
|
applier.Apply(plan);
|
|
|
|
await prov.Called.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
|
prov.Seen.Select(r => (r.TagName, r.DataType)).ShouldBe(new[]
|
|
{
|
|
("P.F", DriverDataType.Float32),
|
|
("P.D", DriverDataType.Float64),
|
|
("P.B", DriverDataType.Int16),
|
|
("P.S", DriverDataType.Int16),
|
|
("P.F32", DriverDataType.Float32),
|
|
}, ignoreOrder: true);
|
|
}
|
|
|
|
/// <summary>lmxopcua#899: a read-only binding (<c>historianReadOnly: true</c>) never reaches EnsureTags — neither
|
|
/// as an add nor as a change. The owned "Control" tag is the positive control, so the absence is not a vacuous
|
|
/// no-dispatch; the override-without-the-flag tag shows the chosen default is unchanged (an override alone still
|
|
/// provisions).</summary>
|
|
[Fact]
|
|
public async Task Apply_never_provisions_a_read_only_binding()
|
|
{
|
|
var prov = new CapturingProvisioner();
|
|
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance, prov);
|
|
|
|
var readOnlyAdded = HistorizedTag("SysTime", "SysTimeSec", "Int32", fullName: "Plant/SysTime") with { HistorianReadOnly = true };
|
|
var flipToReadOnlyOld = HistorizedTag("Pulse", "SysPulse", "Boolean", fullName: "Plant/Pulse");
|
|
var flipToReadOnlyNew = flipToReadOnlyOld with { HistorianReadOnly = true, DataType = "Int32" };
|
|
var readOnlyRenamedOld = HistorizedTag("Ro", "Other.A", "Float", fullName: "Plant/Ro") with { HistorianReadOnly = true };
|
|
var readOnlyRenamedNew = readOnlyRenamedOld with { HistorianTagname = "Other.B" };
|
|
|
|
var plan = PlanWithAddedTags(
|
|
HistorizedTag("Control", "Control.Name", "Float"),
|
|
HistorizedTag("Override", "Someones.Tag", "Double", fullName: "Plant/Override"),
|
|
readOnlyAdded) with
|
|
{
|
|
ChangedRawTags = new[]
|
|
{
|
|
new AddressSpacePlan.RawTagDelta(flipToReadOnlyOld, flipToReadOnlyNew),
|
|
new AddressSpacePlan.RawTagDelta(readOnlyRenamedOld, readOnlyRenamedNew),
|
|
},
|
|
};
|
|
|
|
applier.Apply(plan);
|
|
|
|
await prov.Called.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
|
prov.Seen.Select(r => r.TagName).ShouldBe(new[] { "Control.Name", "Someones.Tag" }, ignoreOrder: true);
|
|
}
|
|
|
|
/// <summary>lmxopcua#899: turning read-only OFF makes the tag owned, so it provisions like a historization flip.</summary>
|
|
[Fact]
|
|
public async Task Apply_provisions_a_tag_whose_read_only_flag_is_cleared()
|
|
{
|
|
var prov = new CapturingProvisioner();
|
|
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance, prov);
|
|
|
|
var before = HistorizedTag("Own", "Mine.Tag", "Float", fullName: "Plant/Own") with { HistorianReadOnly = true };
|
|
var plan = PlanWithAddedTags() with
|
|
{
|
|
ChangedRawTags = new[] { new AddressSpacePlan.RawTagDelta(before, before with { HistorianReadOnly = false }) },
|
|
};
|
|
|
|
applier.Apply(plan);
|
|
|
|
await prov.Called.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
|
prov.Seen.Select(r => r.TagName).ShouldBe(new[] { "Mine.Tag" });
|
|
}
|
|
|
|
/// <summary>#600.1: a CHANGED raw tag that flips to historized, or whose historian name / data type
|
|
/// changes, is provisioned; an unchanged-historization edit and an alarm-bearing tag are not. The
|
|
/// added "Control" tag is the positive control so the absences are not a vacuous no-dispatch.</summary>
|
|
[Fact]
|
|
public async Task Apply_provisions_changed_tags_whose_historization_flips_or_name_changes()
|
|
{
|
|
var prov = new CapturingProvisioner();
|
|
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance, prov);
|
|
|
|
var flipOff = NonHistorizedTag("Flip", "Float32") with { TagId = "t-flip", NodeId = "Plant/Flip" };
|
|
var flipOn = flipOff with { IsHistorized = true };
|
|
var renOld = HistorizedTag("Ren", "Old.Name", "Float32") with { TagId = "t-ren" };
|
|
var renNew = renOld with { HistorianTagname = "New.Name" };
|
|
var sameOld = HistorizedTag("Same", "Same.Name", "Float32") with { TagId = "t-same", Writable = false };
|
|
var sameNew = sameOld with { Writable = true }; // non-historian edit
|
|
var alarmOld = NonHistorizedTag("Alm", "Float32") with { TagId = "t-alm" };
|
|
var alarmNew = alarmOld with
|
|
{
|
|
IsHistorized = true,
|
|
Alarm = new EquipmentTagAlarmInfo("AlarmCondition", 500),
|
|
};
|
|
|
|
var plan = PlanWithAddedTags(HistorizedTag("Control", "Control.Name", "Float32")) with
|
|
{
|
|
ChangedRawTags = new[]
|
|
{
|
|
new AddressSpacePlan.RawTagDelta(flipOff, flipOn),
|
|
new AddressSpacePlan.RawTagDelta(renOld, renNew),
|
|
new AddressSpacePlan.RawTagDelta(sameOld, sameNew),
|
|
new AddressSpacePlan.RawTagDelta(alarmOld, alarmNew),
|
|
},
|
|
};
|
|
|
|
applier.Apply(plan);
|
|
|
|
await prov.Called.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
|
prov.Seen.Select(r => r.TagName).ShouldBe(
|
|
new[] { "Control.Name", "Plant/Flip", "New.Name" }, ignoreOrder: true);
|
|
}
|
|
|
|
/// <summary>Capturing <see cref="ILogger{T}"/> that records every log line and signals a
|
|
/// <see cref="TaskCompletionSource{TResult}"/> the first time a "historian provisioning completed" tally is
|
|
/// emitted, so the fire-and-forget continuation's log can be awaited deterministically.</summary>
|
|
private sealed class CapturingLogger : ILogger<AddressSpaceApplier>
|
|
{
|
|
private readonly TaskCompletionSource<string> _provisioningLogged =
|
|
new(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
|
|
/// <summary>Completes with the rendered message of the first provisioning-completed tally logged.</summary>
|
|
public Task<string> ProvisioningLogged => _provisioningLogged.Task;
|
|
|
|
public IDisposable BeginScope<TState>(TState state) where TState : notnull => NullScope.Instance;
|
|
|
|
public bool IsEnabled(LogLevel logLevel) => true;
|
|
|
|
public void Log<TState>(
|
|
LogLevel logLevel, EventId eventId, TState state, Exception? exception,
|
|
Func<TState, Exception?, string> formatter)
|
|
{
|
|
var message = formatter(state, exception);
|
|
if (logLevel == LogLevel.Information &&
|
|
message.Contains("historian provisioning completed", StringComparison.Ordinal))
|
|
{
|
|
_provisioningLogged.TrySetResult(message);
|
|
}
|
|
}
|
|
|
|
private sealed class NullScope : IDisposable
|
|
{
|
|
public static readonly NullScope Instance = new();
|
|
public void Dispose() { }
|
|
}
|
|
}
|
|
|
|
/// <summary>Issue 2 (observability): a fully-successful provisioning (Ensured>0, Failed=0, Skipped=0) — the
|
|
/// case that previously logged NOTHING — now emits an Information tally, so a successful provisioning is
|
|
/// observable rather than silent.</summary>
|
|
[Fact]
|
|
public async Task Apply_logs_an_information_tally_on_a_fully_successful_provisioning()
|
|
{
|
|
var logger = new CapturingLogger();
|
|
var applier = new AddressSpaceApplier(
|
|
NullOpcUaAddressSpaceSink.Instance, logger, new CapturingProvisioner());
|
|
|
|
applier.Apply(PlanWithAddedTags(
|
|
HistorizedTag(displayName: "Temp", historianName: "Pump1.Temp", dataType: "Float32")));
|
|
|
|
var message = await logger.ProvisioningLogged.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
|
message.ShouldContain("dispatched=1");
|
|
message.ShouldContain("ensured=1");
|
|
message.ShouldContain("failed=0");
|
|
}
|
|
|
|
/// <summary>Issue 2 (observability): the no-op <see cref="NullHistorianProvisioning"/> path is now
|
|
/// DETECTABLE — it reports Requested=0 regardless of input, so a tally showing dispatched=1 but requested=0
|
|
/// unmistakably flags "provisioning is not wired", the invisibility that let the dormant-provisioner bug
|
|
/// ship unnoticed.</summary>
|
|
[Fact]
|
|
public async Task Apply_logs_a_detectable_tally_for_the_noop_provisioning_path()
|
|
{
|
|
var logger = new CapturingLogger();
|
|
var applier = new AddressSpaceApplier(NullOpcUaAddressSpaceSink.Instance, logger);
|
|
|
|
applier.Apply(PlanWithAddedTags(
|
|
HistorizedTag(displayName: "Temp", historianName: "Pump1.Temp", dataType: "Float32")));
|
|
|
|
var message = await logger.ProvisioningLogged.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken);
|
|
message.ShouldContain("dispatched=1"); // we DID hand one request to EnsureTagsAsync
|
|
message.ShouldContain("requested=0"); // ...but the no-op acknowledges nothing ⇒ dormant
|
|
}
|
|
|
|
/// <summary>Capturing <see cref="IHistorizedTagSubscriptionSink"/> double. Records the add/remove
|
|
/// ref deltas the applier feeds it. A <see cref="Throw"/> flag simulates a faulting feed.</summary>
|
|
private sealed class CapturingSubscriptionSink : IHistorizedTagSubscriptionSink
|
|
{
|
|
/// <summary>Ref pairs the applier fed as ADDED (mux ref + historian name).</summary>
|
|
public List<HistorizedTagRef> Added { get; } = new();
|
|
|
|
/// <summary>Ref pairs the applier fed as REMOVED.</summary>
|
|
public List<HistorizedTagRef> Removed { get; } = new();
|
|
|
|
/// <summary>When true, <see cref="UpdateHistorizedRefs"/> throws synchronously.</summary>
|
|
public bool Throw { get; init; }
|
|
|
|
/// <inheritdoc />
|
|
public void UpdateHistorizedRefs(IReadOnlyList<HistorizedTagRef> added, IReadOnlyList<HistorizedTagRef> removed)
|
|
{
|
|
if (Throw) throw new InvalidOperationException("boom");
|
|
Added.AddRange(added);
|
|
Removed.AddRange(removed);
|
|
}
|
|
}
|
|
|
|
/// <summary>The feed pushes ONLY historized added refs, resolved (override-or-FullName) exactly like
|
|
/// the provisioning hook — non-historized tags never reach the recorder.</summary>
|
|
[Fact]
|
|
public void Apply_feeds_historized_added_refs_to_the_subscription_sink()
|
|
{
|
|
var sink = new CapturingSubscriptionSink();
|
|
var applier = new AddressSpaceApplier(
|
|
NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance,
|
|
historizedSubscriptions: sink);
|
|
|
|
var plan = PlanWithAddedTags(
|
|
HistorizedTag(displayName: "Temp", historianName: "Pump1.Temp", dataType: "Float32"),
|
|
HistorizedTag(displayName: "Speed", historianName: null, dataType: "Int32", fullName: "40001"),
|
|
NonHistorizedTag(displayName: "Run", dataType: "Boolean"));
|
|
|
|
applier.Apply(plan);
|
|
|
|
// Each ref carries BOTH identifiers: the override tag feeds (mux ref = FullName "ref", historian
|
|
// name = override "Pump1.Temp"); the no-override tag feeds (FullName "40001" as both).
|
|
sink.Added.ShouldBe(new[]
|
|
{
|
|
new HistorizedTagRef("ref", "Pump1.Temp"),
|
|
new HistorizedTagRef("40001", "40001"),
|
|
}, ignoreOrder: true);
|
|
sink.Removed.ShouldBeEmpty();
|
|
}
|
|
|
|
/// <summary>Removed historized tags are fed as REMOVED refs; a changed tag whose historian override is
|
|
/// renamed feeds the old ref removed + the new ref added (the recorder converges the full set).</summary>
|
|
[Fact]
|
|
public void Apply_feeds_removed_and_renamed_historized_refs()
|
|
{
|
|
var sink = new CapturingSubscriptionSink();
|
|
var applier = new AddressSpaceApplier(
|
|
NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance,
|
|
historizedSubscriptions: sink);
|
|
|
|
var removedTag = HistorizedTag(displayName: "Old", historianName: "Pump1.Old", dataType: "Float32");
|
|
// Same TagId ("tag-T"), historian override renamed A → B (both historized) → remove A, add B.
|
|
var prev = HistorizedTag(displayName: "T", historianName: "Pump1.A", dataType: "Float32");
|
|
var cur = HistorizedTag(displayName: "T", historianName: "Pump1.B", dataType: "Float32");
|
|
|
|
var plan = new AddressSpacePlan(
|
|
AddedEquipment: Array.Empty<EquipmentNode>(),
|
|
RemovedEquipment: Array.Empty<EquipmentNode>(),
|
|
ChangedEquipment: Array.Empty<AddressSpacePlan.EquipmentDelta>(),
|
|
AddedDrivers: Array.Empty<DriverInstancePlan>(),
|
|
RemovedDrivers: Array.Empty<DriverInstancePlan>(),
|
|
ChangedDrivers: Array.Empty<AddressSpacePlan.DriverDelta>(),
|
|
AddedAlarms: Array.Empty<ScriptedAlarmPlan>(),
|
|
RemovedAlarms: Array.Empty<ScriptedAlarmPlan>(),
|
|
ChangedAlarms: Array.Empty<AddressSpacePlan.AlarmDelta>())
|
|
{
|
|
RemovedRawTags = new[] { removedTag },
|
|
ChangedRawTags = new[] { new AddressSpacePlan.RawTagDelta(prev, cur) },
|
|
};
|
|
|
|
applier.Apply(plan);
|
|
|
|
// All three tags default FullName "ref" (the mux ref); the override rename changes only the
|
|
// historian name, so the changed tag feeds removed (ref, Pump1.A) + added (ref, Pump1.B).
|
|
sink.Added.ShouldBe(new[] { new HistorizedTagRef("ref", "Pump1.B") }, ignoreOrder: true);
|
|
sink.Removed.ShouldBe(new[]
|
|
{
|
|
new HistorizedTagRef("ref", "Pump1.Old"),
|
|
new HistorizedTagRef("ref", "Pump1.A"),
|
|
}, ignoreOrder: true);
|
|
}
|
|
|
|
/// <summary>lmxopcua#899: a read-only binding is never fed to the recorder (its WriteLiveValues would write into a
|
|
/// historian tag OtOpcUa does not own); flipping the flag on removes the ref, flipping it off adds it.</summary>
|
|
[Fact]
|
|
public void Apply_never_feeds_a_read_only_binding_to_the_recorder()
|
|
{
|
|
var sink = new CapturingSubscriptionSink();
|
|
var applier = new AddressSpaceApplier(
|
|
NullOpcUaAddressSpaceSink.Instance, NullLogger<AddressSpaceApplier>.Instance,
|
|
historizedSubscriptions: sink);
|
|
|
|
var owned = HistorizedTag("Own", "Mine.Tag", "Float", fullName: "Plant/Own");
|
|
var readOnly = HistorizedTag("Ro", "SysTimeSec", "Int32", fullName: "Plant/Ro") with { HistorianReadOnly = true };
|
|
var goingRo = HistorizedTag("ToRo", "X.Tag", "Float", fullName: "Plant/ToRo");
|
|
var goingOwned = HistorizedTag("ToOwn", "Y.Tag", "Float", fullName: "Plant/ToOwn") with { HistorianReadOnly = true };
|
|
var removedRo = HistorizedTag("Gone", "Z.Tag", "Float", fullName: "Plant/Gone") with { HistorianReadOnly = true };
|
|
|
|
var plan = PlanWithAddedTags(owned, readOnly) with
|
|
{
|
|
RemovedRawTags = new[] { removedRo },
|
|
ChangedRawTags = new[]
|
|
{
|
|
new AddressSpacePlan.RawTagDelta(goingRo, goingRo with { HistorianReadOnly = true }),
|
|
new AddressSpacePlan.RawTagDelta(goingOwned, goingOwned with { HistorianReadOnly = false }),
|
|
},
|
|
};
|
|
|
|
applier.Apply(plan);
|
|
|
|
sink.Added.ShouldBe(new[]
|
|
{
|
|
new HistorizedTagRef("Plant/Own", "Mine.Tag"),
|
|
new HistorizedTagRef("Plant/ToOwn", "Y.Tag"),
|
|
}, ignoreOrder: true);
|
|
sink.Removed.ShouldBe(new[] { new HistorizedTagRef("Plant/ToRo", "X.Tag") });
|
|
}
|
|
|
|
/// <summary>A synchronously-throwing subscription sink must NOT block or break the publish — the
|
|
/// address-space work still completes and <see cref="AddressSpaceApplier.Apply"/> returns its outcome.</summary>
|
|
[Fact]
|
|
public void Subscription_sink_throw_does_not_block_publish()
|
|
{
|
|
var applier = new AddressSpaceApplier(
|
|
NullOpcUaAddressSpaceSink.Instance,
|
|
NullLogger<AddressSpaceApplier>.Instance,
|
|
historizedSubscriptions: new CapturingSubscriptionSink { Throw = true });
|
|
|
|
var outcome = applier.Apply(PlanWithAddedTags(
|
|
HistorizedTag(displayName: "Temp", historianName: "Pump1.Temp", dataType: "Float32")));
|
|
|
|
outcome.RebuildCalled.ShouldBeFalse(); // PureAdd — no rebuild; Apply still completed + provisioned
|
|
}
|
|
|
|
// v3 Batch 4: historized value tags are RAW tags — the mux ref + historian default are the RawPath
|
|
// (== NodeId). The `fullName` param plays the role of the RawPath here (kept as a param name so the
|
|
// existing assertions — HistorizedTagRef("ref"/"40001", …) — read unchanged).
|
|
private static RawTagPlan HistorizedTag(string displayName, string? historianName, string dataType, string fullName = "ref")
|
|
=> new("tag-" + displayName, NodeId: fullName, ParentNodeId: null, DriverInstanceId: "drv", Name: displayName,
|
|
DataType: dataType, Writable: false, Alarm: null, ReferencingEquipmentPaths: Array.Empty<string>(),
|
|
IsHistorized: true, HistorianTagname: historianName);
|
|
|
|
private static RawTagPlan NonHistorizedTag(string displayName, string dataType)
|
|
=> new("tag-" + displayName, NodeId: "ref", ParentNodeId: null, DriverInstanceId: "drv", Name: displayName,
|
|
DataType: dataType, Writable: false, Alarm: null, ReferencingEquipmentPaths: Array.Empty<string>(),
|
|
IsHistorized: false, HistorianTagname: null);
|
|
|
|
private static AddressSpacePlan PlanWithAddedTags(params RawTagPlan[] tags) => new(
|
|
AddedEquipment: Array.Empty<EquipmentNode>(),
|
|
RemovedEquipment: Array.Empty<EquipmentNode>(),
|
|
ChangedEquipment: Array.Empty<AddressSpacePlan.EquipmentDelta>(),
|
|
AddedDrivers: Array.Empty<DriverInstancePlan>(),
|
|
RemovedDrivers: Array.Empty<DriverInstancePlan>(),
|
|
ChangedDrivers: Array.Empty<AddressSpacePlan.DriverDelta>(),
|
|
AddedAlarms: Array.Empty<ScriptedAlarmPlan>(),
|
|
RemovedAlarms: Array.Empty<ScriptedAlarmPlan>(),
|
|
ChangedAlarms: Array.Empty<AddressSpacePlan.AlarmDelta>())
|
|
{
|
|
AddedRawTags = tags,
|
|
};
|
|
}
|