mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-20 00:31:32 +08:00
da7412c429
## Summary - support the xRegistry 0.6.0 distinct Resource/Version hierarchy: `Registry -> Group -> Resource -> Versions -> Version` - instantiate stable logical Resource nodes separately from exact Version nodes while preserving existing Version NodeIds - delegate logical Resource FileType operations and Version-view metadata to the selected default Version with handle pinning and shared writer reservations - make Resource and Version delete behavior role-stable and use `MetaEpoch` / `Epoch` respectively - use stable Resource SourceNodes, exact Version SourceNodes and the `Server -> Registry -> Group -> Resource -> Version` notifier chain - keep a model-metadata-gated client fallback for 0.5 flat Servers; 0.6 Servers expose no legacy aliases - target `HasWoTProjection` at the real stable logical Resource node - use `AsyncCustomNodeManager` for the registration, fast-path, and federation managers, with awaited lifecycle, node mutations, event delivery, and cleanup - handle startup rollback, reentrant deletion callbacks, undisclosed file handles, and retryable cleanup without blocking unrelated file operations ## Authoritative dependencies - companion specification: OPCF-Members/spec-drafts#32 at `d3399fca025025a73e5a6b599f850a81d985c060` - OPC UA binding: xregistry/spec#568 - xRegistry event semantics: xregistry/spec#563, merged as `66ee31e47fbadff6ab982ae1516f7d9065e46b64` - companion NodeSet SHA-256: `369f5f3f1814b333e4eeb52bfb4b6a730cdff372505a5f91a54c94f0016ac4cf` ## Review feedback - keep the WoT Connectivity information-model designation at `1.1`; draft revisions update the publication date without changing the model version - eliminate all 198 unique CA1861 diagnostics across 54 files and remove seven obsolete project suppressions - fix the analyzer-clean touched-path CA1307 and the hierarchy follow-up CA1846/CA1851 diagnostics without dropping legacy-TFM compatibility - recover the reconcile queue after callback faults/cancellation and continue accepted pending changes - remove migration guidance for the xRegistry managers, which are new in 2.0 ## Compatibility - public WoT Connectivity model designation remains `1.1` - generated event-record ABI, constructors, options, NodeIds, and stored documents remain compatible - the generic xRegistry managers are new in 2.0 and implement `IAsyncNodeManager`; use `IAsyncNodeManagerFactory` and the async lifecycle hooks (see `docs\XRegistry.md`) - persistence schema and document blobs remain compatible unless noted below ## Validation - merge validation at `980422f76` with upstream `e8bec27d5`: 454 targeted WoT/materialization/model/registry cases and all 327 XRegistry cases passed on both net10.0 and net48; all 29 net10 aggregation sample cases passed - feedback regressions at `308e8ba74`: 55 targeted queue and live registry event/projection/lifecycle cases passed on each of net10.0 and net48 - prior CI: all 266 checks passed at `6489a0908`; the unchanged Ubuntu Core certificate-counter test and dependent jobs passed on the one-time retry ([run 34117304035, attempt 2](https://github.com/OPCFoundation/UA-.NETStandard/actions/runs/34117304035/attempts/2)) - `Opc.Ua.XRegistry.Tests` — 327 passed on net10.0 and net48 for migration commit `32c914aaf` - `Opc.Ua.WotCon.Tests` net10.0 — 1348 passed - `Opc.Ua.WotCon.Bindings.Tests` net10.0 — 683 passed - `Opc.Ua.SourceGeneration.Core.Tests` net10.0 — 3807 passed, 8 skipped - `Opc.Ua.SourceGeneration.Tests` net10.0 — 145 passed - `Opc.Ua.SourceGeneration.Stack.Tests` net10.0 — 94 passed - affected XRegistry and WoT client/server projects build successfully - xRegistry NodeSet is byte-identical to the companion artifact - repository-wide CA1861 inventory — 198 unique diagnostics across 54 files reduced to zero - targeted changed-fixture validation — 1,098 passed, 3 skipped, 0 failed - constrained full `UA.slnx` net10.0 Release build — CA1861 = 0 - `Opc.Ua.XRegistry.Client` net472 and netstandard2.1 builds — 0 warnings, 0 errors - independent shared-array safety review — no significant issues - `git diff --check` The final review regressions cover concurrent reconcile/open, synthetic logical handle collisions across default switches, cross-session Close isolation, shared writer reservations, logical FileType property/change propagation, logical Labels delegation, role-fixed deletion, event sources, model-version gating, and stable `HasWoTProjection` targets. The companion specification and protocol binding are reviewed in the linked PRs above. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5c79a1ed-6dab-4522-a9fc-6548caa78ad5 Copilot-Session: b605797f-a97a-4cd0-8f12-016d33c2fd88 Copilot-Session: 7ef369a5-2307-4f71-8a11-15af0e72f240 Copilot-Session: e716d455-8397-4d22-9c5a-398847ab7317
337 lines
13 KiB
C#
337 lines
13 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Opc.Ua.Vision;
|
|
using Opc.Ua.Vision.Client;
|
|
|
|
namespace Opc.Ua.Vision.Tests
|
|
{
|
|
/// <summary>
|
|
/// Tests for <see cref="VisionResultReader"/> — snapshot reads for
|
|
/// detection, inspection and segmentation results.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("Vision")]
|
|
public sealed class VisionResultReaderTests
|
|
{
|
|
[Test]
|
|
public async Task ReadInspectionReturnsPopulatedSnapshot()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.ResultId,
|
|
new(3210u, 3), "insp-1");
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.Evaluation,
|
|
new(3211u, 3), (int)VisionResultEvaluationEnum.Ok);
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.PartId,
|
|
new(3212u, 3), "part-A");
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.RecipeId,
|
|
new(3213u, 3), "recipe-1");
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.CreationTime,
|
|
new(3214u, 3), new DateTimeUtc(new DateTime(2024, 1, 1)));
|
|
|
|
VisionResultReader reader = harness.Client.Result(harness.ResultNodeId);
|
|
VisionInspectionResultSnapshot snapshot = await reader.ReadInspectionAsync()
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(snapshot.ResultId, Is.EqualTo("insp-1"));
|
|
Assert.That(snapshot.Evaluation, Is.EqualTo(VisionResultEvaluationEnum.Ok));
|
|
Assert.That(snapshot.PartId, Is.EqualTo("part-A"));
|
|
Assert.That(snapshot.RecipeId, Is.EqualTo("recipe-1"));
|
|
Assert.That(snapshot.NodeId, Is.EqualTo(harness.ResultNodeId));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task ReadDetectionReturnsPopulatedSnapshot()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.ResultId,
|
|
new(3220u, 3), "det-1");
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.FrameId,
|
|
new(3221u, 3), "frame-1");
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.CreationTime,
|
|
new(3222u, 3), new DateTimeUtc(new DateTime(2024, 1, 1)));
|
|
|
|
VisionResultReader reader = harness.Client.Result(harness.ResultNodeId);
|
|
VisionDetectionResultSnapshot snapshot = await reader.ReadDetectionAsync()
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(snapshot.ResultId, Is.EqualTo("det-1"));
|
|
Assert.That(snapshot.FrameId, Is.EqualTo("frame-1"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ReadSegmentationReturnsPopulatedSnapshot()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.ResultId,
|
|
new(3230u, 3), "seg-1");
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.CreationTime,
|
|
new(3231u, 3), new DateTimeUtc(new DateTime(2024, 1, 1)));
|
|
harness.AddValueChild(harness.ResultNodeId, BrowseNames.LabelClasses,
|
|
new(3232u, 3), new Variant(s_stringValues1));
|
|
|
|
VisionResultReader reader = harness.Client.Result(harness.ResultNodeId);
|
|
VisionSegmentationResultSnapshot snapshot = await reader.ReadSegmentationAsync()
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.That(snapshot.ResultId, Is.EqualTo("seg-1"));
|
|
Assert.That(snapshot.LabelClasses.Count, Is.EqualTo(2));
|
|
Assert.That(snapshot.LabelClasses[0], Is.EqualTo("background"));
|
|
}
|
|
|
|
[Test]
|
|
public void ConstructorRejectsNullResultNodeId()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
|
|
Assert.Throws<ArgumentException>(() =>
|
|
harness.Client.Result(NodeId.Null));
|
|
}
|
|
|
|
[Test]
|
|
public void ObserveDetectionsRejectsNullStreaming()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
VisionResultReader reader = harness.Client.Result(harness.ResultNodeId);
|
|
|
|
Assert.Throws<ArgumentNullException>(() =>
|
|
reader.ObserveDetectionsAsync(null!));
|
|
}
|
|
|
|
private static readonly string[] s_stringValues1 = ["background", "part"];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests for <see cref="VisionFrameGraph"/> — frame read, compose,
|
|
/// walk-to-root guards.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("Vision")]
|
|
public sealed class VisionFrameGraphTests
|
|
{
|
|
[Test]
|
|
public async Task ReadReturnsSnapshotWithFrameIdAndTransform()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
var identityTransform = new VisionPose3DDataType
|
|
{
|
|
FrameId = "root",
|
|
Position = s_doubleValues1.ToArrayOf(),
|
|
Orientation = s_doubleValues2.ToArrayOf()
|
|
};
|
|
harness.AddValueChild(harness.FrameNodeId, BrowseNames.FrameId,
|
|
new(4010u, 3), "root");
|
|
harness.AddValueChild(harness.FrameNodeId, BrowseNames.Role,
|
|
new(4011u, 3), (int)VisionFrameRoleEnum.World);
|
|
harness.AddValueChild(harness.FrameNodeId, BrowseNames.Transform,
|
|
new(4013u, 3), Variant.FromStructure(identityTransform));
|
|
|
|
VisionFrameGraph graph = harness.Client.Frames();
|
|
VisionFrameSnapshot snapshot = await graph.ReadAsync(harness.FrameNodeId)
|
|
.ConfigureAwait(false);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(snapshot.FrameId, Is.EqualTo("root"));
|
|
Assert.That(snapshot.Role, Is.EqualTo(VisionFrameRoleEnum.World));
|
|
Assert.That(snapshot.NodeId, Is.EqualTo(harness.FrameNodeId));
|
|
Assert.That(snapshot.Transform, Is.Not.Null);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void ReadRejectsNullFrameNodeId()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
VisionFrameGraph graph = harness.Client.Frames();
|
|
|
|
var ex = Assert.ThrowsAsync<ArgumentException>(async () =>
|
|
await graph.ReadAsync(NodeId.Null).ConfigureAwait(false));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("frameNodeId"));
|
|
}
|
|
|
|
[Test]
|
|
public void ComposeRejectsNullPose()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
VisionFrameGraph graph = harness.Client.Frames();
|
|
|
|
var ex = Assert.ThrowsAsync<ArgumentNullException>(async () =>
|
|
await graph.ComposeAsync(null!, harness.FrameNodeId,
|
|
harness.FrameNodeId).ConfigureAwait(false));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("pose"));
|
|
}
|
|
|
|
[Test]
|
|
public void ComposeRejectsNullFromFrameId()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
VisionFrameGraph graph = harness.Client.Frames();
|
|
var pose = new VisionPose3DDataType();
|
|
|
|
var ex = Assert.ThrowsAsync<ArgumentException>(async () =>
|
|
await graph.ComposeAsync(pose, NodeId.Null, harness.FrameNodeId)
|
|
.ConfigureAwait(false));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("fromFrameId"));
|
|
}
|
|
|
|
[Test]
|
|
public void ComposeRejectsNullToFrameId()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
VisionFrameGraph graph = harness.Client.Frames();
|
|
var pose = new VisionPose3DDataType();
|
|
|
|
var ex = Assert.ThrowsAsync<ArgumentException>(async () =>
|
|
await graph.ComposeAsync(pose, harness.FrameNodeId, NodeId.Null)
|
|
.ConfigureAwait(false));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("toFrameId"));
|
|
}
|
|
|
|
[Test]
|
|
public void ComposeTransformRejectsNullFromFrameId()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
VisionFrameGraph graph = harness.Client.Frames();
|
|
|
|
var ex = Assert.ThrowsAsync<ArgumentException>(async () =>
|
|
await graph.ComposeTransformAsync(NodeId.Null, harness.FrameNodeId)
|
|
.ConfigureAwait(false));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("fromFrameId"));
|
|
}
|
|
|
|
[Test]
|
|
public void ComposeTransformRejectsNullToFrameId()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
VisionFrameGraph graph = harness.Client.Frames();
|
|
|
|
var ex = Assert.ThrowsAsync<ArgumentException>(async () =>
|
|
await graph.ComposeTransformAsync(harness.FrameNodeId, NodeId.Null)
|
|
.ConfigureAwait(false));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("toFrameId"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ComposeTransformReturnsIdentityWhenFromEqualsTo()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
harness.AddValueChild(harness.FrameNodeId, BrowseNames.FrameId,
|
|
new(4020u, 3), "root");
|
|
|
|
VisionFrameGraph graph = harness.Client.Frames();
|
|
VisionPose3DDataType transform = await graph.ComposeTransformAsync(
|
|
harness.FrameNodeId, harness.FrameNodeId).ConfigureAwait(false);
|
|
|
|
Assert.That(transform, Is.Not.Null);
|
|
Assert.That(transform.Orientation.Count, Is.GreaterThanOrEqualTo(4),
|
|
"An identity quaternion has four components.");
|
|
}
|
|
|
|
private static readonly double[] s_doubleValues1 = [0.0, 0.0, 0.0];
|
|
private static readonly double[] s_doubleValues2 = [0.0, 0.0, 0.0, 1.0];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tests for <see cref="VisionClientFactory"/> and
|
|
/// <see cref="SessionVisionExtensions"/>.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("Vision")]
|
|
public sealed class VisionClientFactoryTests
|
|
{
|
|
[Test]
|
|
public void ConstructorRejectsNullSessionFactory()
|
|
{
|
|
var telemetry = new Moq.Mock<ITelemetryContext>().Object;
|
|
|
|
var ex = Assert.Throws<ArgumentNullException>(() =>
|
|
new VisionClientFactory(null!, telemetry));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("sessionFactory"));
|
|
}
|
|
|
|
[Test]
|
|
public void ConstructorRejectsNullTelemetry()
|
|
{
|
|
var ex = Assert.Throws<ArgumentNullException>(() =>
|
|
new VisionClientFactory(
|
|
_ => Task.FromResult<Opc.Ua.Client.ManagedSession>(null!),
|
|
null!));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("telemetry"));
|
|
}
|
|
|
|
[Test]
|
|
public void SessionVisionRejectsNullSession()
|
|
{
|
|
var telemetry = new Moq.Mock<ITelemetryContext>().Object;
|
|
|
|
var ex = Assert.Throws<ArgumentNullException>(() =>
|
|
SessionVisionExtensions.Vision(null!, telemetry));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("session"));
|
|
}
|
|
|
|
[Test]
|
|
public void SessionVisionRejectsNullTelemetry()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
|
|
var ex = Assert.Throws<ArgumentNullException>(() =>
|
|
harness.Session.Object.Vision(null!));
|
|
|
|
Assert.That(ex!.ParamName, Is.EqualTo("telemetry"));
|
|
}
|
|
|
|
[Test]
|
|
public void SessionVisionReturnsVisionClientBoundToSession()
|
|
{
|
|
var harness = new VisionSessionHarness();
|
|
|
|
VisionClient client = harness.Session.Object.Vision(harness.Telemetry);
|
|
|
|
Assert.That(client, Is.Not.Null);
|
|
Assert.That(client.Session, Is.SameAs(harness.Session.Object));
|
|
}
|
|
}
|
|
}
|