fix(grpc-data): H3 review D1/D4/D6/D7 — probe cancel, sub-batches, flush wake-up, request-order budget
D1: a caller cancel (the projected deadline) during the connection's capability probe escaped as RpcException(Cancelled) and faulted the whole HistoryRead; it is now OperationCanceledException, the probe is capped by HistoryTimeout, and ProjectedHistoryAccess fails any escaping fault per node (BadTimeout when the deadline fired) and releases every cursor it owns. D4: calls are sub-batched at min(the deployed connection's batch, the origin's advertised MaxBatchItems) and at most one item per 256 B of the remaining assembly budget; a shortfall is BadTooManyOperations per node, never an endpoint failure. D6: the release flush is re-armed from a flag under its gate (no lost wake-up) and the stop source is never disposed under a running flush. D7: calls are runs of consecutive request positions read in request order, then the budget is charged in request order. Float32 node over a Double-returning backend reads Good Singles end to end (no KindMatches defect). Red/green for D1/D4/D7 by mutation; D6's race did not reproduce red.
This commit is contained in:
+31
@@ -193,6 +193,31 @@ public sealed class GrpcDataHistoryClientTests
|
||||
await Should.ThrowAsync<OperationCanceledException>(() => connection.ReadHistoryAsync(Request(), cancel.Token));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Phase", "H3")]
|
||||
public async Task A_caller_cancel_during_the_capability_probe_is_an_OperationCanceledException_never_an_RpcException()
|
||||
{
|
||||
// H3 review D1: the probe that never answers used to surface RpcException(Cancelled) and fault the consumer's HistoryRead.
|
||||
var a = new Endpoint("a") { ProbeDelay = TimeSpan.FromSeconds(30) };
|
||||
await using var connection = Connect([a]);
|
||||
using var cancel = new CancellationTokenSource(TimeSpan.FromMilliseconds(200));
|
||||
var error = await Should.ThrowAsync<OperationCanceledException>(() => connection.ReadHistoryAsync(Request(), cancel.Token));
|
||||
error.ShouldNotBeAssignableTo<Grpc.Core.RpcException>();
|
||||
a.HistoryCalls.ShouldBe(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Phase", "H3")]
|
||||
public async Task The_capability_probe_is_capped_by_HistoryTimeout_too()
|
||||
{
|
||||
var a = new Endpoint("a");
|
||||
await using var connection = Connect([a], historyTimeout: TimeSpan.FromSeconds(2));
|
||||
var request = Request() with { Budget = Request().Budget with { Timeout = TimeSpan.FromMinutes(10) } };
|
||||
(await connection.ReadHistoryAsync(request, TestContext.Current.CancellationToken)).Single().StatusCode.ShouldBe(0u);
|
||||
a.LastProbeTimeout.ShouldNotBeNull();
|
||||
a.LastProbeTimeout!.Value.ShouldBeLessThanOrEqualTo(TimeSpan.FromSeconds(2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_failure_mid_assembly_releases_the_origin_chunk_tokens_it_holds()
|
||||
{
|
||||
@@ -225,6 +250,10 @@ public sealed class GrpcDataHistoryClientTests
|
||||
public bool Malformed { get; set; }
|
||||
/// <summary>Delay before answering a HistoryRead (honours the request's token).</summary>
|
||||
public TimeSpan? Delay { get; set; }
|
||||
/// <summary>Delay before answering the capability probe (honours the request's token).</summary>
|
||||
public TimeSpan? ProbeDelay { get; set; }
|
||||
/// <summary>The grpc-timeout of the last capability probe.</summary>
|
||||
public TimeSpan? LastProbeTimeout { get; private set; }
|
||||
/// <summary>Fail every HistoryRead after the first with this status.</summary>
|
||||
public Grpc.Core.StatusCode? FailAfterFirst { get; set; }
|
||||
public int Chunks { get; init; } = 1;
|
||||
@@ -247,6 +276,8 @@ public sealed class GrpcDataHistoryClientTests
|
||||
IMessage message;
|
||||
if (path.EndsWith("/GetCapabilities", StringComparison.Ordinal))
|
||||
{
|
||||
if (request.Headers.TryGetValues("grpc-timeout", out var probeTimeouts)) LastProbeTimeout = ParseTimeout(probeTimeouts.Single());
|
||||
if (ProbeDelay is { } probeDelay) await Task.Delay(probeDelay, token);
|
||||
var asked = request.Headers.Contains("x-otopcua-data-features");
|
||||
var caps = DataProtoMapper.EncodeCapabilities(new DataCapabilities(1, 5, Serving, Ready ? DataReadiness.Ready : DataReadiness.Unavailable,
|
||||
!Ready ? DataOperations.None : DataOperationSets.V1 | (history && asked && Granted ? DataOperations.HistoryRead : DataOperations.None),
|
||||
|
||||
Reference in New Issue
Block a user