test(grpc-data): A2b recorded-v1 gate (fake origin) — CallConditionMethod only with conditions; goldens unchanged
This commit is contained in:
+36
-3
@@ -31,6 +31,29 @@ public sealed class GrpcDataV1CompatibilityTests
|
|||||||
{
|
{
|
||||||
/// <summary>Every RPC of the v1 service, in the order <see cref="GrpcDataV1Goldens"/> records them.</summary>
|
/// <summary>Every RPC of the v1 service, in the order <see cref="GrpcDataV1Goldens"/> records them.</summary>
|
||||||
internal static readonly string[] RpcNames = ["GetCapabilities", "Browse", "GetMetadata", "Read", "Write", "Subscribe"];
|
internal static readonly string[] RpcNames = ["GetCapabilities", "Browse", "GetMetadata", "Read", "Write", "Subscribe"];
|
||||||
|
/// <summary>
|
||||||
|
/// A2b: the fake origin grants the method bits and implements the method port; a header-less (or history-only) call
|
||||||
|
/// is refused FAILED_PRECONDITION before the origin, and the capabilities golden is unchanged (no bits 128/256).
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public async Task A2b_CallConditionMethod_is_served_only_on_a_call_that_negotiated_conditions()
|
||||||
|
{
|
||||||
|
var request = ZB.MOM.WW.OtOpcUa.Commons.DataConnections.DataConditionProtoMapper.EncodeMethodRequest(new DataConditionMethodRequest(
|
||||||
|
"op", V1Requests.Raw, DataConditionMethods.Acknowledge, new("inc", 1), null, "boot", TimeSpan.FromSeconds(5))).ToByteArray();
|
||||||
|
var before = Volatile.Read(ref V1CompatibilityHarness.Origin.MethodCalls);
|
||||||
|
foreach (var header in new[] { "", "history" })
|
||||||
|
{
|
||||||
|
var headers = header.Length == 0 ? new Metadata() : new Metadata { { "x-otopcua-data-features", header } };
|
||||||
|
(await Should.ThrowAsync<RpcException>(() => V1CompatibilityHarness.DriveAsync("CallConditionMethod", headers, request: request)))
|
||||||
|
.StatusCode.ShouldBe(StatusCode.FailedPrecondition);
|
||||||
|
}
|
||||||
|
Volatile.Read(ref V1CompatibilityHarness.Origin.MethodCalls).ShouldBe(before);
|
||||||
|
var response = W.ConditionMethodResponse.Parser.ParseFrom(Convert.FromHexString(await V1CompatibilityHarness.DriveAsync(
|
||||||
|
"CallConditionMethod", new Metadata { { "x-otopcua-data-features", "conditions" } }, request: request)));
|
||||||
|
response.State.ShouldBe((int)DataWriteState.DriverConfirmedSuccess);
|
||||||
|
(await V1CompatibilityHarness.DriveAsync("GetCapabilities", new Metadata())).ShouldBe(GrpcDataV1Goldens.Responses["GetCapabilities"]);
|
||||||
|
}
|
||||||
|
|
||||||
public static TheoryData<string> Rpcs => new(RpcNames);
|
public static TheoryData<string> Rpcs => new(RpcNames);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -281,6 +304,7 @@ internal static class V1CompatibilityHarness
|
|||||||
"GetMetadata" => await service.GetMetadata(W.MetadataRequest.Parser.ParseFrom(bytes), context),
|
"GetMetadata" => await service.GetMetadata(W.MetadataRequest.Parser.ParseFrom(bytes), context),
|
||||||
"Read" => await service.Read(W.ReadRequest.Parser.ParseFrom(bytes), context),
|
"Read" => await service.Read(W.ReadRequest.Parser.ParseFrom(bytes), context),
|
||||||
"Write" => await service.Write(W.WriteRequest.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!,
|
"Subscribe" => null!,
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(rpc)),
|
_ => throw new ArgumentOutOfRangeException(nameof(rpc)),
|
||||||
};
|
};
|
||||||
@@ -316,13 +340,22 @@ internal static class V1CompatibilityHarness
|
|||||||
{
|
{
|
||||||
public IDataConnection Create(DataAuthenticatedContext context, DataTarget target) =>
|
public IDataConnection Create(DataAuthenticatedContext context, DataTarget target) =>
|
||||||
new Origin(target, (history ? operations | DataOperations.HistoryRead : operations)
|
new Origin(target, (history ? operations | DataOperations.HistoryRead : operations)
|
||||||
| (conditions && operations.HasFlag(DataOperations.Subscribe) ? DataOperations.AlarmSubscribe : DataOperations.None),
|
| (conditions && operations.HasFlag(DataOperations.Subscribe) ? DataOperationSets.ConditionGrants : DataOperations.None),
|
||||||
history, conditions);
|
history, conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>A deterministic v1 origin exercising every optional v1 field the encoders emit.</summary>
|
/// <summary>A deterministic v1 origin exercising every optional v1 field the encoders emit.</summary>
|
||||||
private sealed class Origin(DataTarget target, DataOperations operations, bool history, bool conditions) : IDataConnection, IDataConnectionPublicationGate, IDataConnectionDiscoveryGate
|
internal sealed class Origin(DataTarget target, DataOperations operations, bool history, bool conditions) : IDataConnection, IDataConnectionPublicationGate, IDataConnectionDiscoveryGate,
|
||||||
|
IDataConditionMethodService
|
||||||
{
|
{
|
||||||
|
/// <summary>A2b: every method call that reached this origin (static: one harness per test call).</summary>
|
||||||
|
internal static int MethodCalls;
|
||||||
|
public Task<DataConditionMethodResult> CallConditionMethodAsync(DataConditionMethodRequest request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
Interlocked.Increment(ref MethodCalls);
|
||||||
|
return Task.FromResult(new DataConditionMethodResult(DataWriteState.DriverConfirmedSuccess, 0, null, Serving));
|
||||||
|
}
|
||||||
|
|
||||||
internal static readonly ServingIdentity Serving = new("node", "boot", "Primary", 1, 1, 1);
|
internal static readonly ServingIdentity Serving = new("node", "boot", "Primary", 1, 1, 1);
|
||||||
private static readonly DateTimeOffset Source = new(2026, 11, 23, 12, 0, 0, TimeSpan.Zero);
|
private static readonly DateTimeOffset Source = new(2026, 11, 23, 12, 0, 0, TimeSpan.Zero);
|
||||||
private static readonly DateTimeOffset Server = Source.AddMilliseconds(250);
|
private static readonly DateTimeOffset Server = Source.AddMilliseconds(250);
|
||||||
@@ -337,7 +370,7 @@ internal static class V1CompatibilityHarness
|
|||||||
new(16, 16, 65_536, 16, 4, 65_536, TimeSpan.FromSeconds(30), TimeSpan.FromMinutes(10), TimeSpan.FromSeconds(5), 1000),
|
new(16, 16, 65_536, 16, 4, 65_536, TimeSpan.FromSeconds(30), TimeSpan.FromMinutes(10), TimeSpan.FromSeconds(5), 1000),
|
||||||
false, 0, "cluster", true, true, true, true, true,
|
false, 0, "cluster", true, true, true, true, true,
|
||||||
history ? new DataHistoryCapabilities(true, true, true, ["Average"], 1, 10_000, 4, TimeSpan.FromSeconds(60)) : null,
|
history ? new DataHistoryCapabilities(true, true, true, ["Average"], 1, 10_000, 4, TimeSpan.FromSeconds(60)) : null,
|
||||||
conditions ? new DataConditionCapabilities(true, 0, 1000) : null));
|
conditions ? new DataConditionCapabilities(true, 7, 1000) : null));
|
||||||
|
|
||||||
// H2 new-shape data: HistoryRead granted, HistoryInfo present (the service strips both from a header-less call).
|
// H2 new-shape data: HistoryRead granted, HistoryInfo present (the service strips both from a header-less call).
|
||||||
private DataMetadata Scalar => new(V1Requests.Raw, "Speed", "Variable", DataValueKind.Int32, -1, [], true,
|
private DataMetadata Scalar => new(V1Requests.Raw, "Speed", "Variable", DataValueKind.Int32, -1, [], true,
|
||||||
|
|||||||
Reference in New Issue
Block a user