test(grpc-data): A2b recorded-v1 gate (real origin) — method bits granted, header-less golden unchanged, CallConditionMethod FAILED_PRECONDITION without conditions
This commit is contained in:
+49
-3
@@ -113,6 +113,46 @@ public sealed class GrpcDataV1RealOriginCompatibilityTests
|
||||
.ShouldBe(GrpcDataV1RealOriginGoldens.Responses["GetCapabilities"], "header-less: no field 17, no bit 64");
|
||||
}
|
||||
|
||||
/// <summary>A2b: a call that did not negotiate <c>conditions</c> never reaches the origin's method port.</summary>
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("history")]
|
||||
public async Task A2b_CallConditionMethod_without_the_conditions_feature_is_FAILED_PRECONDITION_and_never_dispatched(string header)
|
||||
{
|
||||
await using var origin = new RealOrigin();
|
||||
var headers = header.Length == 0 ? new Metadata() : new Metadata { { "x-otopcua-data-features", header } };
|
||||
var error = await Should.ThrowAsync<RpcException>(() => origin.DriveAsync("CallConditionMethod", headers, MethodRequest()));
|
||||
error.StatusCode.ShouldBe(StatusCode.FailedPrecondition);
|
||||
origin.ConditionPort!.Calls.ShouldBeEmpty();
|
||||
// And an origin that cannot serve conditions refuses it the same way even with the header.
|
||||
await using var noConditions = new RealOrigin(conditions: false);
|
||||
(await Should.ThrowAsync<RpcException>(() => noConditions.DriveAsync("CallConditionMethod",
|
||||
new Metadata { { "x-otopcua-data-features", "conditions" } }, MethodRequest()))).StatusCode.ShouldBe(StatusCode.FailedPrecondition);
|
||||
}
|
||||
|
||||
/// <summary>A2b: with the header, capabilities carry the method bits + mask and the call reaches the origin port once.</summary>
|
||||
[Fact]
|
||||
public async Task A2b_a_condition_capable_real_origin_serves_CallConditionMethod_only_with_the_header()
|
||||
{
|
||||
await using var origin = new RealOrigin();
|
||||
var caps = W.CapabilitiesResponse.Parser.ParseFrom(Convert.FromHexString(
|
||||
await origin.DriveAsync("GetCapabilities", new Metadata { { "x-otopcua-data-features", "conditions" } })));
|
||||
(caps.Operations & 384u).ShouldBe(384u);
|
||||
caps.Conditions.Methods.ShouldBe(7u);
|
||||
var response = W.ConditionMethodResponse.Parser.ParseFrom(Convert.FromHexString(
|
||||
await origin.DriveAsync("CallConditionMethod", new Metadata { { "x-otopcua-data-features", "conditions" } }, MethodRequest())));
|
||||
response.State.ShouldBe((int)DataWriteState.AcceptedUnconfirmed);
|
||||
response.Serving.Incarnation.ShouldBe(RealOrigin.Incarnation);
|
||||
origin.ConditionPort!.Calls.ShouldHaveSingleItem().ShouldSatisfyAllConditions(
|
||||
c => c.ConditionId.ShouldBe("Plant/Modbus/dev1/HighTemp"), c => c.Principal.ShouldBe("peer"), c => c.Method.ShouldBe("Acknowledge"));
|
||||
(await origin.DriveAsync("GetCapabilities", new Metadata()))
|
||||
.ShouldBe(GrpcDataV1RealOriginGoldens.Responses["GetCapabilities"], "header-less: no field 17, no bits 64/128/256");
|
||||
}
|
||||
|
||||
private static byte[] MethodRequest() => DataConditionProtoMapper.EncodeMethodRequest(new DataConditionMethodRequest("op-1",
|
||||
RealOriginRequests.HighTemp, DataConditionMethods.Acknowledge, new("inc", 0), "ack", RealOrigin.Incarnation, TimeSpan.FromSeconds(5),
|
||||
"remote operator")).ToByteArray();
|
||||
|
||||
public static TheoryData<string, string> V1Rejections()
|
||||
{
|
||||
var data = new TheoryData<string, string>();
|
||||
@@ -295,7 +335,9 @@ internal sealed class RealOrigin : IAsyncDisposable
|
||||
// H2 new-shape data: every export also grants HistoryRead (header-less callers must never see it).
|
||||
// A2a new-shape data: every export also grants AlarmSubscribe and the origin serves conditions (the HighTemp alarm).
|
||||
var granted = (grantHistory ? exportOperations | DataOperations.HistoryRead : exportOperations)
|
||||
| (conditions && exportOperations.HasFlag(DataOperations.Subscribe) ? DataOperations.AlarmSubscribe : DataOperations.None);
|
||||
| (conditions && exportOperations.HasFlag(DataOperations.Subscribe) ? DataOperations.AlarmSubscribe : DataOperations.None)
|
||||
// A2b new-shape data: the same exports also grant the method bits (header-less callers must never see them).
|
||||
| (conditions && exportOperations.HasFlag(DataOperations.Subscribe) ? DataOperationSets.ConditionMethods : DataOperations.None);
|
||||
var catalog = LocalExportCatalog.Compile(Snapshot(granted, concurrentReads, responseBytes, valuesPerPage),
|
||||
Serving, activation.CaptureAuthority());
|
||||
|
||||
@@ -328,7 +370,7 @@ internal sealed class RealOrigin : IAsyncDisposable
|
||||
targetSubscriptions: (context, target) => new LocalSubscriptionService(services!, context, target, new Demand(), sessionLimits, transport),
|
||||
history: History)
|
||||
{
|
||||
ConditionHub = conditions ? ConditionHub : null, ConditionSource = conditions ? new SingleConditionSource(ConditionHub) : null,
|
||||
ConditionHub = conditions ? ConditionHub : null, ConditionSource = conditions ? ConditionPort = new SingleConditionSource(ConditionHub) : null,
|
||||
ConditionKeysSource = () => conditions ? ConditionKeys.FromSecret(ConditionSecret) : ConditionKeys.Unavailable,
|
||||
};
|
||||
_services = services;
|
||||
@@ -338,6 +380,9 @@ internal sealed class RealOrigin : IAsyncDisposable
|
||||
internal IReadOnlyList<string> Dispatched => _route.Dispatched;
|
||||
|
||||
private const string ConditionSecret = "a2-real-origin-condition-key-secret-0123456789";
|
||||
|
||||
/// <summary>A2b: the node-manager condition port (null when the origin serves no conditions).</summary>
|
||||
internal SingleConditionSource? ConditionPort { get; private set; }
|
||||
internal readonly ConditionStateHub ConditionHub = new(new PrimaryRole());
|
||||
|
||||
private sealed class PrimaryRole : ZB.MOM.WW.OtOpcUa.Core.Abstractions.IDriverPrimaryRoleSource
|
||||
@@ -347,7 +392,7 @@ internal sealed class RealOrigin : IAsyncDisposable
|
||||
}
|
||||
|
||||
/// <summary>The node manager's snapshot semantics for the one alarm-bearing raw tag (HighTemp), inactive and known.</summary>
|
||||
private sealed class SingleConditionSource(ConditionStateHub hub) : ZB.MOM.WW.OtOpcUa.OpcUaServer.IOriginConditionSource
|
||||
internal sealed class SingleConditionSource(ConditionStateHub hub) : ZB.MOM.WW.OtOpcUa.OpcUaServer.IOriginConditionSource
|
||||
{
|
||||
public IReadOnlyList<ZB.MOM.WW.OtOpcUa.OpcUaServer.ConditionSnapshotSlice> SnapshotConditions(
|
||||
Func<ZB.MOM.WW.OtOpcUa.Commons.OpcUa.AddressSpaceRealm, string, bool> scope, int maxConditionsPerHold)
|
||||
@@ -480,6 +525,7 @@ internal sealed class RealOrigin : IAsyncDisposable
|
||||
"GetMetadata" => await service.GetMetadata(W.MetadataRequest.Parser.ParseFrom(bytes), context),
|
||||
"Read" => await service.Read(W.ReadRequest.Parser.ParseFrom(bytes), context),
|
||||
"Write" => await service.Write(W.WriteRequest.Parser.ParseFrom(bytes), context),
|
||||
"CallConditionMethod" => await service.CallConditionMethod(W.ConditionMethodRequest.Parser.ParseFrom(bytes), context),
|
||||
"Subscribe" => null!,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(scenario)),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user