mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-27 04:59:55 +08:00
## 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
295 lines
12 KiB
C#
295 lines
12 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;
|
|
using System.Threading.Tasks;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Opc.Ua.Client;
|
|
using Opc.Ua.WotCon.Client;
|
|
using Opc.Ua.XRegistry;
|
|
|
|
namespace Opc.Ua.WotCon.Tests.Client
|
|
{
|
|
/// <summary>
|
|
/// Unit tests for the shared <c>TranslateBrowsePaths</c> helper every
|
|
/// WoT Connectivity client wrapper uses to resolve a named child. The
|
|
/// interesting behaviour is what it does with the degenerate
|
|
/// responses a non-conformant server can legitimately return.
|
|
/// </summary>
|
|
[TestFixture]
|
|
[Category("WotCon")]
|
|
[Category("Client")]
|
|
[SetCulture("en-us")]
|
|
[SetUICulture("en-us")]
|
|
public sealed class WotConBrowsePathResolverTests
|
|
{
|
|
[Test]
|
|
public async Task ResolveChildReturnsTheTranslatedTargetNodeIdAsync()
|
|
{
|
|
BrowsePath? captured = null;
|
|
var target = new NodeId("WoTRegistry", 3);
|
|
Mock<ISession> session = CreateSession(
|
|
path =>
|
|
{
|
|
captured = path;
|
|
return new BrowsePathResult
|
|
{
|
|
StatusCode = StatusCodes.Good,
|
|
Targets = new[]
|
|
{
|
|
new BrowsePathTarget
|
|
{
|
|
TargetId = target,
|
|
RemainingPathIndex = uint.MaxValue
|
|
}
|
|
}.ToArrayOf()
|
|
};
|
|
});
|
|
|
|
NodeId resolved = await WotConBrowsePathResolver.ResolveChildAsync(
|
|
session.Object,
|
|
Ua.ObjectIds.Server,
|
|
Ua.ReferenceTypeIds.HasComponent,
|
|
3,
|
|
"WoTRegistry",
|
|
StatusCodes.BadNodeIdUnknown,
|
|
"not found",
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
Assert.That(resolved, Is.EqualTo(target));
|
|
Assert.That(captured, Is.Not.Null);
|
|
Assert.That(captured!.StartingNode, Is.EqualTo(Ua.ObjectIds.Server));
|
|
Assert.That(captured.RelativePath.Elements, Has.Count.EqualTo(1));
|
|
RelativePathElement element = captured.RelativePath.Elements[0];
|
|
Assert.That(element.ReferenceTypeId, Is.EqualTo(Ua.ReferenceTypeIds.HasComponent));
|
|
Assert.That(element.IsInverse, Is.False);
|
|
Assert.That(element.IncludeSubtypes, Is.True);
|
|
Assert.That(element.TargetName, Is.EqualTo(new QualifiedName("WoTRegistry", 3)));
|
|
}
|
|
|
|
[Test]
|
|
public void ResolveChildThrowsTheSuppliedStatusWhenNoResultIsReturned()
|
|
{
|
|
Mock<ISession> session = CreateSession(_ => null);
|
|
|
|
ServiceResultException ex = Assert.ThrowsAsync<ServiceResultException>(
|
|
async () => await ResolveAsync(session).ConfigureAwait(false))!;
|
|
|
|
Assert.That(ex.StatusCode, Is.EqualTo(StatusCodes.BadNoMatch));
|
|
Assert.That(ex.Message, Does.Contain("missing"));
|
|
}
|
|
|
|
[Test]
|
|
public void ResolveChildThrowsTheSuppliedStatusWhenNoTargetIsReturned()
|
|
{
|
|
Mock<ISession> session = CreateSession(
|
|
_ => new BrowsePathResult { StatusCode = StatusCodes.Good, Targets = [] });
|
|
|
|
ServiceResultException ex = Assert.ThrowsAsync<ServiceResultException>(
|
|
async () => await ResolveAsync(session).ConfigureAwait(false))!;
|
|
|
|
Assert.That(ex.StatusCode, Is.EqualTo(StatusCodes.BadNoMatch));
|
|
}
|
|
|
|
[Test]
|
|
public void ResolveChildThrowsTheSuppliedStatusWhenTheServerReportsABadResult()
|
|
{
|
|
Mock<ISession> session = CreateSession(
|
|
_ => new BrowsePathResult
|
|
{
|
|
StatusCode = StatusCodes.BadNoMatch,
|
|
Targets = new[]
|
|
{
|
|
new BrowsePathTarget
|
|
{
|
|
TargetId = new NodeId("ignored", 3),
|
|
RemainingPathIndex = uint.MaxValue
|
|
}
|
|
}.ToArrayOf()
|
|
});
|
|
|
|
ServiceResultException ex = Assert.ThrowsAsync<ServiceResultException>(
|
|
async () => await ResolveAsync(session).ConfigureAwait(false))!;
|
|
|
|
Assert.That(ex.StatusCode, Is.EqualTo(StatusCodes.BadNoMatch));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ResolveLogicalResourceSelectsDefaultFromCollidingBrowseNames()
|
|
{
|
|
var telemetry = new Mock<ITelemetryContext>();
|
|
var messageContext = ServiceMessageContext.Create(telemetry.Object);
|
|
ushort wotNs = messageContext.NamespaceUris.GetIndexOrAppend(Namespaces.WotCon);
|
|
ushort xRegistryNs = messageContext.NamespaceUris.GetIndexOrAppend(
|
|
XRegistryWellKnown.XRegistryNamespaceUri);
|
|
var group = new NodeId("group", wotNs);
|
|
var nonDefault = new NodeId("non-default", wotNs);
|
|
var expected = new NodeId("default", wotNs);
|
|
var nonDefaultResourceId = new NodeId("non-default/resourceid", xRegistryNs);
|
|
var nonDefaultFlag = new NodeId("non-default/isdefault", wotNs);
|
|
var defaultResourceId = new NodeId("default/resourceid", xRegistryNs);
|
|
var defaultFlag = new NodeId("default/isdefault", wotNs);
|
|
var session = new Mock<ISession>(MockBehavior.Strict);
|
|
session.SetupGet(s => s.NamespaceUris).Returns(messageContext.NamespaceUris);
|
|
session
|
|
.Setup(s => s.BrowseAsync(
|
|
It.IsAny<RequestHeader>(),
|
|
It.IsAny<ViewDescription>(),
|
|
It.IsAny<uint>(),
|
|
It.IsAny<ArrayOf<BrowseDescription>>(),
|
|
It.IsAny<CancellationToken>()))
|
|
.Returns<RequestHeader, ViewDescription, uint, ArrayOf<BrowseDescription>,
|
|
CancellationToken>((_, _, _, descriptions, _) =>
|
|
{
|
|
NodeId parent = descriptions[0].NodeId;
|
|
ReferenceDescription[] references = parent == group
|
|
?
|
|
[
|
|
Child(nonDefault, "collision", wotNs),
|
|
Child(expected, "collision", wotNs)
|
|
]
|
|
: parent == nonDefault
|
|
?
|
|
[
|
|
Child(nonDefaultResourceId, "ResourceId", xRegistryNs),
|
|
Child(nonDefaultFlag, "IsDefault", wotNs)
|
|
]
|
|
:
|
|
[
|
|
Child(defaultResourceId, "ResourceId", xRegistryNs),
|
|
Child(defaultFlag, "IsDefault", wotNs)
|
|
];
|
|
return new ValueTask<BrowseResponse>(new BrowseResponse
|
|
{
|
|
ResponseHeader = new ResponseHeader(),
|
|
Results = new[]
|
|
{
|
|
new BrowseResult
|
|
{
|
|
StatusCode = StatusCodes.Good,
|
|
References = references.ToArrayOf()
|
|
}
|
|
}.ToArrayOf(),
|
|
DiagnosticInfos = default
|
|
});
|
|
});
|
|
session
|
|
.Setup(s => s.ReadAsync(
|
|
It.IsAny<RequestHeader>(),
|
|
It.IsAny<double>(),
|
|
It.IsAny<TimestampsToReturn>(),
|
|
It.IsAny<ArrayOf<ReadValueId>>(),
|
|
It.IsAny<CancellationToken>()))
|
|
.Returns<RequestHeader, double, TimestampsToReturn, ArrayOf<ReadValueId>,
|
|
CancellationToken>((_, _, _, reads, _) =>
|
|
{
|
|
bool isDefault = reads[1].NodeId == defaultFlag;
|
|
return new ValueTask<ReadResponse>(new ReadResponse
|
|
{
|
|
ResponseHeader = new ResponseHeader(),
|
|
Results = new[]
|
|
{
|
|
new DataValue(new Variant("collision")),
|
|
new DataValue(new Variant(isDefault))
|
|
}.ToArrayOf(),
|
|
DiagnosticInfos = default
|
|
});
|
|
});
|
|
|
|
NodeId resolved = await WotConBrowsePathResolver.ResolveLogicalResourceAsync(
|
|
session.Object,
|
|
group,
|
|
wotNs,
|
|
"collision",
|
|
StatusCodes.BadNoMatch,
|
|
"missing",
|
|
CancellationToken.None).ConfigureAwait(false);
|
|
|
|
Assert.That(resolved, Is.EqualTo(expected));
|
|
}
|
|
|
|
private static ReferenceDescription Child(
|
|
NodeId nodeId,
|
|
string browseName,
|
|
ushort namespaceIndex)
|
|
{
|
|
return new ReferenceDescription
|
|
{
|
|
ReferenceTypeId = Ua.ReferenceTypeIds.HierarchicalReferences,
|
|
IsForward = true,
|
|
NodeId = nodeId,
|
|
BrowseName = new QualifiedName(browseName, namespaceIndex),
|
|
DisplayName = new LocalizedText(browseName),
|
|
NodeClass = NodeClass.Variable
|
|
};
|
|
}
|
|
|
|
private static ValueTask<NodeId> ResolveAsync(Mock<ISession> session)
|
|
{
|
|
return WotConBrowsePathResolver.ResolveChildAsync(
|
|
session.Object,
|
|
Ua.ObjectIds.Server,
|
|
Ua.ReferenceTypeIds.Organizes,
|
|
3,
|
|
"missing",
|
|
StatusCodes.BadNoMatch,
|
|
"Group 'missing' not found in the registry.",
|
|
CancellationToken.None);
|
|
}
|
|
|
|
private static Mock<ISession> CreateSession(Func<BrowsePath, BrowsePathResult?> resolve)
|
|
{
|
|
var telemetry = new Mock<ITelemetryContext>();
|
|
var messageContext = ServiceMessageContext.Create(telemetry.Object);
|
|
var session = new Mock<ISession>(MockBehavior.Strict);
|
|
session.SetupGet(s => s.NamespaceUris).Returns(messageContext.NamespaceUris);
|
|
session
|
|
.Setup(s => s.TranslateBrowsePathsToNodeIdsAsync(
|
|
It.IsAny<RequestHeader>(),
|
|
It.IsAny<ArrayOf<BrowsePath>>(),
|
|
It.IsAny<CancellationToken>()))
|
|
.Returns<RequestHeader, ArrayOf<BrowsePath>, CancellationToken>(
|
|
(_, paths, _) =>
|
|
{
|
|
BrowsePathResult? result = resolve(paths[0]);
|
|
return new ValueTask<TranslateBrowsePathsToNodeIdsResponse>(
|
|
new TranslateBrowsePathsToNodeIdsResponse
|
|
{
|
|
ResponseHeader = new ResponseHeader(),
|
|
Results = result is null ? [] : new[] { result }.ToArrayOf(),
|
|
DiagnosticInfos = default
|
|
});
|
|
});
|
|
return session;
|
|
}
|
|
}
|
|
}
|