mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-20 16:52:07 +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
376 lines
15 KiB
C#
376 lines
15 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.Collections.Concurrent;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using NUnit.Framework;
|
|
using Opc.Ua.Robotics.Server;
|
|
using Opc.Ua.RobotIntent;
|
|
using Opc.Ua.RobotIntent.Server;
|
|
using Opc.Ua.Tests;
|
|
using RiDataTypeIds = Opc.Ua.RobotIntent.DataTypeIds;
|
|
using RiNamespaces = Opc.Ua.RobotIntent.Namespaces;
|
|
|
|
namespace Opc.Ua.Robotics.Tests
|
|
{
|
|
/// <summary>
|
|
/// Verifies host refusals that protect narrowed Robot Intent interoperability claims.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class IntentControllerHostStructuralFailureTests
|
|
{
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
ITelemetryContext telemetry = NUnitTelemetryContext.Create(true);
|
|
ServiceMessageContext messageContext = ServiceMessageContext.Create(telemetry);
|
|
messageContext.NamespaceUris.Append(RiNamespaces.RobotIntent);
|
|
m_context = new SystemContext(telemetry)
|
|
{
|
|
NamespaceUris = messageContext.NamespaceUris,
|
|
EncodeableFactory = messageContext.Factory
|
|
};
|
|
m_executor = new RecordingExecutor();
|
|
}
|
|
|
|
[Test]
|
|
public void SubmitIntentRejectsFastenJointNarrowingBeforeExecution()
|
|
{
|
|
using IntentControllerHost host = NewHost();
|
|
|
|
IntentAdmission admission = host.SubmitIntent(m_context, null, new FastenIntentDataType
|
|
{
|
|
Joint = new NodeId("joint", 1),
|
|
TargetTorque = 1.0
|
|
});
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(admission.Accepted, Is.False);
|
|
Assert.That(admission.Failure, Is.EqualTo(IntentFailureEnum.CapabilityNotSupported));
|
|
Assert.That(admission.Message, Does.Contain("OPC 40450/40451"));
|
|
Assert.That(m_executor.Started.ToArray(), Is.Empty);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void SubmitMissionRejectsFastenJointNarrowingBeforeCreatingMission()
|
|
{
|
|
using IntentControllerHost host = NewHost();
|
|
|
|
MissionAdmission admission = host.SubmitMission(m_context, null, new MissionDataType
|
|
{
|
|
MissionId = "m1",
|
|
Steps = new[]
|
|
{
|
|
Step("s1", 1, new FastenIntentDataType
|
|
{
|
|
Joint = new NodeId("joint", 1),
|
|
TargetTorque = 1.0
|
|
})
|
|
}
|
|
});
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(admission.Accepted, Is.False);
|
|
Assert.That(admission.Failure, Is.EqualTo(IntentFailureEnum.CapabilityNotSupported));
|
|
Assert.That(admission.Message, Does.Contain("OPC 40450/40451"));
|
|
Assert.That(m_executor.Started.ToArray(), Is.Empty);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task MissionFailsWithNoTransitionWhenSelectedTransitionTargetsMissingStep()
|
|
{
|
|
IntentControllerHostOptions options = Options();
|
|
options.MissionBranchingSupported = true;
|
|
using IntentControllerHost host = NewHost(options);
|
|
|
|
m_executor.Gate = new SemaphoreSlim(0);
|
|
var missionData = new MissionDataType
|
|
{
|
|
MissionId = "m1",
|
|
Steps = new[] { Step("s1", 1, Move("s1")), Step("s2", 2, Move("s2")) },
|
|
Transitions = new[] { Transition("s1", "s2") }
|
|
};
|
|
|
|
MissionAdmission admission = host.SubmitMission(m_context, null, missionData);
|
|
|
|
Assert.That(admission.Accepted, Is.True, admission.Message);
|
|
await WaitAsync(() => !m_executor.Started.IsEmpty).ConfigureAwait(false);
|
|
missionData.Steps = new[] { missionData.Steps[0] }.ToArrayOf();
|
|
m_executor.Gate.Release();
|
|
await WaitAsync(() => MissionReached(ExecutionStateEnum.Failed)).ConfigureAwait(false);
|
|
|
|
MissionObjectState mission = m_executor.Added.OfType<MissionObjectState>().Single();
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(m_executor.Started.ToArray(), Is.EqualTo(s_stringValues1));
|
|
Assert.That(mission.ExecutionState!.Value, Is.EqualTo(ExecutionStateEnum.Failed));
|
|
Assert.That(MissionFailure(mission), Is.EqualTo(IntentFailureEnum.NoTransition));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task GraphedMissionSucceedsWhenFinalStepHasNoOutgoingTransition()
|
|
{
|
|
IntentControllerHostOptions options = Options();
|
|
options.MissionBranchingSupported = true;
|
|
using IntentControllerHost host = NewHost(options);
|
|
|
|
MissionAdmission admission = host.SubmitMission(m_context, null, new MissionDataType
|
|
{
|
|
MissionId = "m1",
|
|
Steps = new[] { Step("s1", 1, Move("s1")), Step("s2", 2, Move("s2")) },
|
|
Transitions = new[] { Transition("s1", "s2") }
|
|
});
|
|
|
|
Assert.That(admission.Accepted, Is.True, admission.Message);
|
|
await WaitAsync(() => MissionReached(ExecutionStateEnum.Succeeded)).ConfigureAwait(false);
|
|
|
|
MissionObjectState mission = m_executor.Added.OfType<MissionObjectState>().Single();
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(m_executor.Started.ToArray(), Is.EqualTo(s_stringValues2));
|
|
Assert.That(mission.ExecutionState!.Value, Is.EqualTo(ExecutionStateEnum.Succeeded));
|
|
Assert.That(MissionFailure(mission), Is.EqualTo(IntentFailureEnum.None));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task BranchPointFailsWithNoTransitionWhenNoConditionMatches()
|
|
{
|
|
IntentControllerHostOptions options = Options();
|
|
options.MissionBranchingSupported = true;
|
|
using IntentControllerHost host = NewHost(options);
|
|
|
|
MissionAdmission admission = host.SubmitMission(m_context, null, new MissionDataType
|
|
{
|
|
MissionId = "m1",
|
|
Steps = new[] { Step("s1", 1, Move("s1")), Step("s2", 2, Move("s2")) },
|
|
Transitions = new[] { Transition("s1", "s2", NonEmptyFilter()) }
|
|
});
|
|
|
|
Assert.That(admission.Accepted, Is.True, admission.Message);
|
|
await WaitAsync(() => MissionReached(ExecutionStateEnum.Failed)).ConfigureAwait(false);
|
|
|
|
MissionObjectState mission = m_executor.Added.OfType<MissionObjectState>().Single();
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(m_executor.Started.ToArray(), Is.EqualTo(s_stringValues1));
|
|
Assert.That(mission.ExecutionState!.Value, Is.EqualTo(ExecutionStateEnum.Failed));
|
|
Assert.That(MissionFailure(mission), Is.EqualTo(IntentFailureEnum.NoTransition));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task UngraphedMissionStillSucceedsSequentially()
|
|
{
|
|
using IntentControllerHost host = NewHost();
|
|
|
|
MissionAdmission admission = host.SubmitMission(m_context, null, new MissionDataType
|
|
{
|
|
MissionId = "m1",
|
|
Steps = new[] { Step("s1", 1, Move("s1")), Step("s2", 2, Move("s2")) }
|
|
});
|
|
|
|
Assert.That(admission.Accepted, Is.True, admission.Message);
|
|
await WaitAsync(() => MissionReached(ExecutionStateEnum.Succeeded)).ConfigureAwait(false);
|
|
|
|
MissionObjectState mission = m_executor.Added.OfType<MissionObjectState>().Single();
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(m_executor.Started.ToArray(), Is.EqualTo(s_stringValues2));
|
|
Assert.That(mission.ExecutionState!.Value, Is.EqualTo(ExecutionStateEnum.Succeeded));
|
|
Assert.That(MissionFailure(mission), Is.EqualTo(IntentFailureEnum.None));
|
|
});
|
|
}
|
|
|
|
private IntentControllerHost NewHost(IntentControllerHostOptions? options = null)
|
|
{
|
|
var controller = new IntentControllerState(null);
|
|
controller.Create(
|
|
m_context,
|
|
new NodeId(Guid.NewGuid().ToString(), 1),
|
|
new QualifiedName("Controller", 1),
|
|
new LocalizedText("Controller"),
|
|
true);
|
|
var host = new IntentControllerHost(
|
|
controller,
|
|
m_executor,
|
|
(node, _) =>
|
|
{
|
|
m_executor.Added.Enqueue(node);
|
|
return default;
|
|
},
|
|
options ?? Options());
|
|
host.Start(m_context);
|
|
return host;
|
|
}
|
|
|
|
private bool MissionReached(ExecutionStateEnum state)
|
|
{
|
|
return m_executor.Added
|
|
.OfType<MissionObjectState>()
|
|
.Any(mission => mission.ExecutionState?.Value == state);
|
|
}
|
|
|
|
private static IntentControllerHostOptions Options()
|
|
{
|
|
var options = new IntentControllerHostOptions
|
|
{
|
|
RequireControlAuthority = false,
|
|
AxisCount = 6,
|
|
MaxQueueDepth = 8
|
|
};
|
|
options.Accept(RiDataTypeIds.LinearMoveIntentDataType);
|
|
options.Accept(RiDataTypeIds.FastenIntentDataType);
|
|
return options;
|
|
}
|
|
|
|
private static MissionStepDataType Step(string id, uint sequence, IntentDataType intent)
|
|
{
|
|
intent.IntentId = id;
|
|
return new MissionStepDataType
|
|
{
|
|
StepId = id,
|
|
SequenceId = sequence,
|
|
Intent = intent
|
|
};
|
|
}
|
|
|
|
private static LinearMoveIntentDataType Move(string id)
|
|
{
|
|
return new LinearMoveIntentDataType
|
|
{
|
|
IntentId = id,
|
|
Target = new Pose3DDataType
|
|
{
|
|
FrameId = "base",
|
|
Position = new[] { 1.0, 0.0, 0.0 },
|
|
Orientation = new[] { 0.0, 0.0, 0.0, 1.0 }
|
|
}
|
|
};
|
|
}
|
|
|
|
private static MissionTransitionDataType Transition(
|
|
string from,
|
|
string to,
|
|
ContentFilter? condition = null)
|
|
{
|
|
return new MissionTransitionDataType
|
|
{
|
|
FromStepId = from,
|
|
ToStepId = to,
|
|
DivergenceKind = DivergenceKindEnum.Alternative,
|
|
Condition = condition ?? new ContentFilter()
|
|
};
|
|
}
|
|
|
|
private IntentFailureEnum MissionFailure(MissionObjectState mission)
|
|
{
|
|
Assert.That(mission.FinalResultData, Is.Not.Null);
|
|
NodeState? child = mission.FinalResultData!.FindChild(
|
|
m_context,
|
|
new QualifiedName(nameof(IntentResultDataType.Failure), mission.BrowseName.NamespaceIndex));
|
|
Assert.That(child, Is.InstanceOf<BaseDataVariableState>());
|
|
BaseDataVariableState failure = (BaseDataVariableState)child!;
|
|
Assert.That(failure, Is.Not.Null);
|
|
Assert.That(failure.Value, Is.TypeOf<Variant>());
|
|
var value = (Variant)failure.Value;
|
|
Assert.That(value.TryGetValue(out int result), Is.True);
|
|
return (IntentFailureEnum)result;
|
|
}
|
|
|
|
private static ContentFilter NonEmptyFilter()
|
|
{
|
|
return new ContentFilter
|
|
{
|
|
Elements = new[] { new ContentFilterElement { FilterOperator = FilterOperator.IsNull } }
|
|
};
|
|
}
|
|
|
|
private static async Task WaitAsync(Func<bool> condition)
|
|
{
|
|
DateTime deadline = DateTime.UtcNow.AddSeconds(5);
|
|
while (DateTime.UtcNow < deadline)
|
|
{
|
|
if (condition())
|
|
{
|
|
return;
|
|
}
|
|
await Task.Delay(10).ConfigureAwait(false);
|
|
}
|
|
Assert.Fail("timed out waiting for the expected condition");
|
|
}
|
|
|
|
private SystemContext m_context = null!;
|
|
private RecordingExecutor m_executor = null!;
|
|
|
|
private sealed class RecordingExecutor : IIntentExecutor
|
|
{
|
|
public ConcurrentQueue<NodeState> Added { get; } = new();
|
|
public ConcurrentQueue<string> Started { get; } = new();
|
|
public SemaphoreSlim? Gate { get; set; }
|
|
|
|
public ValueTask<IntentOutcome> ExecuteAsync(
|
|
IntentExecution execution,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
Started.Enqueue(execution.Intent.IntentId ?? execution.IntentId);
|
|
if (Gate != null)
|
|
{
|
|
return AwaitGateAsync(Gate, cancellationToken);
|
|
}
|
|
return new ValueTask<IntentOutcome>(IntentOutcome.Success);
|
|
}
|
|
|
|
private static async ValueTask<IntentOutcome> AwaitGateAsync(
|
|
SemaphoreSlim gate,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
await gate.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
return IntentOutcome.Success;
|
|
}
|
|
|
|
public bool CanCancel(IntentExecution execution)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private static readonly string[] s_stringValues1 = ["s1"];
|
|
private static readonly string[] s_stringValues2 = ["s1", "s2"];
|
|
}
|
|
}
|