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),
|
||||
|
||||
+3
-3
@@ -134,7 +134,7 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
bool advanceAuthority = false, string role = "Primary", long servingGeneration = 0, bool nestedCatalog = false, bool nestedUnsCatalog = false,
|
||||
Func<DataAuthenticatedContext, IDataWriteService>? writes = null, bool denyReadExport = false,
|
||||
ManualTimeProvider? clock = null, string servingNode = "node-a", string servingIncarnation = "serving-1",
|
||||
IOriginHistoryPort? history = null)
|
||||
IOriginHistoryPort? history = null, DataValueKind rawValueKind = DataValueKind.Int32, int maxBatchItems = 100)
|
||||
{
|
||||
if (clock is not null) Clock = clock;
|
||||
Serving = Serving with { NodeId = servingNode, Incarnation = servingIncarnation, Role = role, ServingGeneration = servingGeneration };
|
||||
@@ -163,7 +163,7 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
if (denyReadExport) operations &= ~DataOperations.Read;
|
||||
if (history is not null) operations |= DataOperations.HistoryRead;
|
||||
var rootMetadata = new DataMetadata(Root, "Plant", "Folder", DataValueKind.Null, -1, [], false, operations, 1, null, null, false);
|
||||
var rawMetadata = new DataMetadata(Raw, "Speed", "Variable", DataValueKind.Int32, -1, [], true, operations, 1, Ticket.Key.StableSourceId, "rpm", false);
|
||||
var rawMetadata = new DataMetadata(Raw, "Speed", "Variable", rawValueKind, -1, [], true, operations, 1, Ticket.Key.StableSourceId, "rpm", false);
|
||||
var unsMetadata = rawMetadata with { View = Uns };
|
||||
var folder = Root with { Address = Root.Address with { Identifier = "Plant/Driver" }, Subject = "Plant/Driver" };
|
||||
var unsRoot = Uns with { Address = Uns.Address with { Identifier = "Area" }, Subject = "Area" };
|
||||
@@ -192,7 +192,7 @@ internal sealed class LocalDataFixture : IDisposable
|
||||
Catalog = new LocalExportCatalog("cluster", Serving, Activation.CaptureAuthority(), nodes,
|
||||
[new() { DataExportId = "raw-export", ClusterId = "cluster", Enabled = true, Realm = DataRealm.Raw, RootKind = "RawFolder", RootEntityId = "folder", PrincipalId = "peer", AllowedOperations = operations },
|
||||
new() { DataExportId = "uns-export", ClusterId = "cluster", Enabled = true, Realm = DataRealm.Uns, RootKind = nestedUnsCatalog ? "UnsArea" : "UnsTagReference", RootEntityId = nestedUnsCatalog ? "area" : "reference", PrincipalId = "peer", AllowedOperations = operations }]);
|
||||
var limits = new DataLimits(100, 100, 1_000_000, 100, 10, 1_000_000, TimeSpan.FromSeconds(15), TimeSpan.FromHours(1), TimeSpan.FromMinutes(1));
|
||||
var limits = new DataLimits(100, maxBatchItems, 1_000_000, 100, 10, 1_000_000, TimeSpan.FromSeconds(15), TimeSpan.FromHours(1), TimeSpan.FromMinutes(1));
|
||||
var capabilities = new DataCapabilitiesProvider("cluster", () => Serving, () => Catalog.IsActive, limits);
|
||||
Services = new LocalDataServices(() => Catalog, Hub, new DataOperationPolicy(Authority,
|
||||
new TriePermissionEvaluator(Authority.Tries, Clock), Clock), capabilities, Clock, writes: writes, subscriptions: subscriptions,
|
||||
|
||||
+218
-4
@@ -240,6 +240,151 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests
|
||||
}, localPermissions: 15, allowHistory: granted, connectionSource: new PersistentConnections(origin));
|
||||
}
|
||||
|
||||
[Fact(Timeout = 90000)]
|
||||
[Trait("Phase", "H3")]
|
||||
public async Task A_Float32_node_whose_backend_returns_Double_reads_Good_through_the_projection_as_it_does_locally()
|
||||
{
|
||||
// H3 review: SQL backends store every float as a Double. The origin port normalises Raw / AtTime to the node's type
|
||||
// (Single) before the wire, so the projected rows are Good Singles — never a BadTypeMismatch per row while local works.
|
||||
await using var originServer = await HistoryOrigin.StartAsync(5, dataType: "Float", value: i => i + 0.5);
|
||||
using var origin = new LocalDataFixture(servingGeneration: 1, history: originServer.Port, rawValueKind: DataValueKind.Float);
|
||||
await WithComposedServer(origin, origin.Raw, async (session, _, _, _, _, _, anchor) =>
|
||||
{
|
||||
var client = (SessionClient)session;
|
||||
await BrowseAll(client, anchor, 1);
|
||||
var raw = await RawHistory(client, anchor, 0, default);
|
||||
StatusCode.IsGood(raw.StatusCode).ShouldBeTrue(raw.StatusCode.ToString());
|
||||
var values = Values(raw);
|
||||
values.Count.ShouldBe(5);
|
||||
values.ShouldAllBe(v => StatusCode.IsGood(v.StatusCode));
|
||||
values.Select(v => SdkValueBoundary.ToClr(v.WrappedValue)).ShouldBe(Enumerable.Range(0, 5).Select(i => (object?)(float)(i + 0.5)));
|
||||
var details = new ReadAtTimeDetails { ReqTimes = [(DateTimeUtc)HistoryT0.AddSeconds(2)] };
|
||||
var response = await client.HistoryReadAsync(new RequestHeader(), new ExtensionObject(details), TimestampsToReturn.Both, false,
|
||||
[new HistoryReadValueId { NodeId = anchor }], TestContext.Current.CancellationToken);
|
||||
var atTime = Values(response.Results.ToArray()!.Single()).ShouldHaveSingleItem();
|
||||
StatusCode.IsGood(atTime.StatusCode).ShouldBeTrue(atTime.StatusCode.ToString());
|
||||
SdkValueBoundary.ToClr(atTime.WrappedValue).ShouldBeOfType<float>().ShouldBe(2.5f);
|
||||
}, localPermissions: 15, allowHistory: true, connectionSource: new PersistentConnections(origin));
|
||||
}
|
||||
|
||||
[Theory(Timeout = 90000)]
|
||||
[Trait("Phase", "H3")]
|
||||
[InlineData(HistoryMode.Hang)]
|
||||
[InlineData(HistoryMode.Throw)]
|
||||
public async Task A_history_call_that_never_answers_or_faults_fails_only_the_projected_half_and_releases_its_cursor(HistoryMode mode)
|
||||
{
|
||||
// H3 review D1: a deadline during the connection's capability probe used to escape as an RpcException and fault the
|
||||
// whole HistoryRead. Now the projected half fails per node (BadTimeout when the deadline fired), the local half of the
|
||||
// same batch is served, and the claimed origin cursor is released (positive control: the origin store returns to 0).
|
||||
await using var originServer = await HistoryOrigin.StartAsync(7);
|
||||
using var origin = new LocalDataFixture(servingGeneration: 1, history: originServer.Port);
|
||||
var connections = new HistorySwitchConnections(origin);
|
||||
ProjectedHistoryAccess? history = null;
|
||||
OtOpcUaNodeManager? manager = null;
|
||||
await WithComposedServer(origin, origin.Raw, async (session, _, _, _, _, _, anchor) =>
|
||||
{
|
||||
var client = (SessionClient)session;
|
||||
await BrowseAll(client, anchor, 1);
|
||||
manager!.HistorianDataSource = new SeriesSource(Enumerable.Range(0, 3)
|
||||
.Select(i => new DataValueSnapshot(i, 0, HistoryT0.AddSeconds(i), HistoryT0.AddSeconds(i))).ToArray());
|
||||
manager.EnsureVariable("Plant/LocalH", "Plant", "LocalH", "Int32", false, AddressSpaceRealm.Raw, historianTagname: "local");
|
||||
var local = manager.TryGetVariable("Plant/LocalH", AddressSpaceRealm.Raw)!.NodeId;
|
||||
var page = await RawHistory(client, anchor, 2, default);
|
||||
page.ContinuationPoint.IsEmpty.ShouldBeFalse();
|
||||
origin.Services.HistoryOpenContinuations.ShouldBe(1);
|
||||
|
||||
connections.Mode = mode;
|
||||
manager.HistoryReadDeadline = TimeSpan.FromSeconds(1);
|
||||
var response = await client.HistoryReadAsync(new RequestHeader { TimeoutHint = 20_000 }, new ExtensionObject(RawDetails(2)),
|
||||
TimestampsToReturn.Both, false,
|
||||
[new HistoryReadValueId { NodeId = local }, new HistoryReadValueId { NodeId = anchor, ContinuationPoint = page.ContinuationPoint }],
|
||||
TestContext.Current.CancellationToken);
|
||||
var results = response.Results.ToArray()!;
|
||||
StatusCode.IsGood(results[0].StatusCode).ShouldBeTrue("the local half of the batch is still served");
|
||||
Values(results[0]).Count.ShouldBe(2);
|
||||
results[1].StatusCode.Code.ShouldBe(mode == HistoryMode.Hang ? StatusCodes.BadTimeout.Code : StatusCodes.BadContinuationPointInvalid.Code);
|
||||
await AwaitReleases(history!, () => origin.Services.HistoryOpenContinuations == 0);
|
||||
origin.Services.HistoryOpenContinuations.ShouldBe(0, "the claimed cursor's origin continuation was released");
|
||||
}, localPermissions: 15, allowHistory: true, connectionSource: connections, onHistory: (h, m) => { history = h; manager = m; });
|
||||
}
|
||||
|
||||
[Fact(Timeout = 90000)]
|
||||
[Trait("Phase", "H3")]
|
||||
public async Task A_group_larger_than_the_origin_batch_is_split_into_sub_batches()
|
||||
{
|
||||
// H3 review D4: three projected nodes against an origin that admits two items per request.
|
||||
await using var originServer = await HistoryOrigin.StartAsync(7, extra: 2);
|
||||
using var origin = new LocalDataFixture(additionalRawNodes: 2, servingGeneration: 1, history: originServer.Port, maxBatchItems: 2);
|
||||
var connections = new HistorySwitchConnections(origin);
|
||||
await WithComposedServer(origin, origin.Root, async (session, _, _, _, _, _, anchor) =>
|
||||
{
|
||||
var client = (SessionClient)session;
|
||||
var children = (await BrowseAll(client, anchor, 10)).Select(r => ExpandedNodeId.ToNodeId(r.NodeId, session.NamespaceUris)).ToArray();
|
||||
children.Length.ShouldBe(3);
|
||||
var response = await client.HistoryReadAsync(new RequestHeader(), new ExtensionObject(RawDetails(3)), TimestampsToReturn.Both, false,
|
||||
children.Select(c => new HistoryReadValueId { NodeId = c }).ToArray(), TestContext.Current.CancellationToken);
|
||||
var results = response.Results.ToArray()!;
|
||||
results.ShouldAllBe(r => StatusCode.IsGood(r.StatusCode));
|
||||
results.ShouldAllBe(r => Values(r).Count == 3);
|
||||
connections.HistoryCallSizes.ShouldBe([2, 1]);
|
||||
foreach (var r in results) await RawHistory(client, children[Array.IndexOf(results, r)], 3, r.ContinuationPoint);
|
||||
}, localPermissions: 15, allowHistory: true, connectionSource: connections);
|
||||
}
|
||||
|
||||
[Fact(Timeout = 90000)]
|
||||
[Trait("Phase", "H3")]
|
||||
public async Task The_assembly_budget_is_charged_in_request_order_across_groups()
|
||||
{
|
||||
// H3 review D7: request [A fresh, B resumed, C fresh] runs as two groups ({A, C} then {B}); with room for two nodes the
|
||||
// refused one must be C — the last in REQUEST order — not B.
|
||||
await using var originServer = await HistoryOrigin.StartAsync(7, extra: 2);
|
||||
using var origin = new LocalDataFixture(additionalRawNodes: 2, servingGeneration: 1, history: originServer.Port);
|
||||
await WithComposedServer(origin, origin.Root, async (session, _, _, _, _, _, anchor) =>
|
||||
{
|
||||
var client = (SessionClient)session;
|
||||
var children = (await BrowseAll(client, anchor, 10)).Select(r => ExpandedNodeId.ToNodeId(r.NodeId, session.NamespaceUris)).ToArray();
|
||||
children.Length.ShouldBe(3);
|
||||
var first = await RawHistory(client, children[1], 3, default);
|
||||
first.ContinuationPoint.IsEmpty.ShouldBeFalse();
|
||||
var response = await client.HistoryReadAsync(new RequestHeader(), new ExtensionObject(RawDetails(3)), TimestampsToReturn.Both, false,
|
||||
[new HistoryReadValueId { NodeId = children[0] }, new HistoryReadValueId { NodeId = children[1], ContinuationPoint = first.ContinuationPoint },
|
||||
new HistoryReadValueId { NodeId = children[2] }], TestContext.Current.CancellationToken);
|
||||
var results = response.Results.ToArray()!;
|
||||
StatusCode.IsGood(results[0].StatusCode).ShouldBeTrue(results[0].StatusCode.ToString());
|
||||
StatusCode.IsGood(results[1].StatusCode).ShouldBeTrue("the resumed node is second in request order: it fits");
|
||||
results[2].StatusCode.Code.ShouldBe(StatusCodes.BadTooManyOperations.Code);
|
||||
Values(results[2]).ShouldBeEmpty();
|
||||
}, localPermissions: 15, allowHistory: true, connectionSource: new PersistentConnections(origin),
|
||||
configureMapping: m => m.MaxHistoryAssemblyBytesPerRequest = 2 * 3 * 288 + 100); // ≈ 288 B a value: two 3-value nodes fit
|
||||
}
|
||||
|
||||
[Fact(Timeout = 90000)]
|
||||
[Trait("Phase", "H3")]
|
||||
public async Task Releases_queued_while_a_flush_is_finishing_are_never_lost()
|
||||
{
|
||||
// H3 review D6: the flush used to be re-armed from Task.IsCompleted, so a token queued after its last check but before it
|
||||
// completed waited for the NEXT release — or forever. Many concurrent enqueues must all reach the connection.
|
||||
await using var originServer = await HistoryOrigin.StartAsync(1);
|
||||
using var origin = new LocalDataFixture(servingGeneration: 1, history: originServer.Port);
|
||||
var connections = new HistorySwitchConnections(origin);
|
||||
ProjectedHistoryAccess? history = null;
|
||||
await WithComposedServer(origin, origin.Raw, async (_, _, _, _, _, _, _) =>
|
||||
{
|
||||
const int count = 2000;
|
||||
await Task.WhenAll(Enumerable.Range(0, 8).Select(t => Task.Run(() =>
|
||||
{
|
||||
for (var i = t; i < count; i += 8) history!.EnqueueReleaseForTests("link", BitConverter.GetBytes(i));
|
||||
})));
|
||||
var deadline = DateTime.UtcNow.AddSeconds(20);
|
||||
while (connections.ReleasedTokens < count && DateTime.UtcNow < deadline)
|
||||
{
|
||||
await history!.FlushReleasesForTestsAsync();
|
||||
await Task.Delay(10, TestContext.Current.CancellationToken);
|
||||
}
|
||||
connections.ReleasedTokens.ShouldBe(count);
|
||||
}, localPermissions: 15, allowHistory: true, connectionSource: connections, onHistory: (h, _) => history = h);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private static ReadRawModifiedDetails RawDetails(uint count) => new()
|
||||
@@ -278,6 +423,73 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests
|
||||
}
|
||||
}
|
||||
|
||||
public enum HistoryMode { Pass, Hang, Throw }
|
||||
|
||||
/// <summary>
|
||||
/// One long-lived origin connection whose HISTORY path can be switched to never answer (then fault as a cancelled gRPC call,
|
||||
/// as a probe cancelled by its deadline did) or to fault at once; releases always pass through and are counted.
|
||||
/// </summary>
|
||||
private sealed class HistorySwitchConnections(LocalDataFixture peer) : IGrpcDataAdapterConnectionSource
|
||||
{
|
||||
private IDataConnection? _inner;
|
||||
private readonly object _gate = new();
|
||||
private int _released;
|
||||
private readonly List<int> _sizes = [];
|
||||
public HistoryMode Mode { get; set; }
|
||||
public int ReleasedTokens => Volatile.Read(ref _released);
|
||||
public IReadOnlyList<int> HistoryCallSizes { get { lock (_sizes) return _sizes.ToArray(); } }
|
||||
|
||||
public ValueTask<IGrpcDataAdapterConnectionLease?> AcquireAsync(string connectionId, CancellationToken cancellationToken)
|
||||
{
|
||||
if (connectionId != "link") return ValueTask.FromResult<IGrpcDataAdapterConnectionLease?>(null);
|
||||
lock (_gate) _inner ??= peer.Connection();
|
||||
return ValueTask.FromResult<IGrpcDataAdapterConnectionLease?>(new Borrowed(new Switch(_inner, this), _gate));
|
||||
}
|
||||
|
||||
private sealed class Borrowed(IDataConnection connection, object route) : IGrpcDataAdapterConnectionLease
|
||||
{
|
||||
public IDataConnection Connection => connection;
|
||||
public CancellationToken CancellationToken => CancellationToken.None;
|
||||
public object? RouteIdentity => route;
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
private sealed class Switch(IDataConnection inner, HistorySwitchConnections owner) : IDataConnection, IDataHistoryService
|
||||
{
|
||||
public DataTarget Target => inner.Target;
|
||||
public TimeProvider Clock => inner.Clock;
|
||||
public Task<DataCapabilities> GetCapabilitiesAsync(DataBudget budget, CancellationToken cancellationToken) => inner.GetCapabilitiesAsync(budget, cancellationToken);
|
||||
public Task<DataBrowseBranch> BrowseAsync(ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.BrowseRequest request, CancellationToken cancellationToken) => inner.BrowseAsync(request, cancellationToken);
|
||||
public Task<IReadOnlyList<DataItemResult<DataMetadata>>> GetMetadataAsync(MetadataRequest request, CancellationToken cancellationToken) => inner.GetMetadataAsync(request, cancellationToken);
|
||||
public Task<IReadOnlyList<ReadResult>> ReadAsync(ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.ReadRequest request, CancellationToken cancellationToken) => inner.ReadAsync(request, cancellationToken);
|
||||
public Task<IReadOnlyList<WriteItemResult>> WriteAsync(WriteBatch request, CancellationToken cancellationToken) => inner.WriteAsync(request, cancellationToken);
|
||||
public Task<IDataSubscription> SubscribeAsync(CancellationToken cancellationToken) => inner.SubscribeAsync(cancellationToken);
|
||||
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
||||
|
||||
public async Task<IReadOnlyList<DataHistoryReadResult>> ReadAsync(DataHistoryReadRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
lock (owner._sizes) owner._sizes.Add(request.Items.Count);
|
||||
switch (owner.Mode)
|
||||
{
|
||||
case HistoryMode.Hang:
|
||||
try { await Task.Delay(Timeout.Infinite, cancellationToken); }
|
||||
catch (OperationCanceledException ex)
|
||||
{ throw new Grpc.Core.RpcException(new Grpc.Core.Status(Grpc.Core.StatusCode.Cancelled, "probe cancelled", ex)); }
|
||||
break;
|
||||
case HistoryMode.Throw:
|
||||
throw new Grpc.Core.RpcException(new Grpc.Core.Status(Grpc.Core.StatusCode.Internal, "boom"));
|
||||
}
|
||||
return await ((IDataHistoryService)inner).ReadAsync(request, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task ReleaseAsync(IReadOnlyList<byte[]> continuations, CancellationToken cancellationToken)
|
||||
{
|
||||
Interlocked.Add(ref owner._released, continuations.Count);
|
||||
await ((IDataHistoryService)inner).ReleaseAsync(continuations, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>One long-lived origin connection, as a deployed gRPC connection is; <see cref="Rotate"/> replaces it (a redeploy).</summary>
|
||||
private sealed class PersistentConnections(LocalDataFixture peer) : IGrpcDataAdapterConnectionSource
|
||||
{
|
||||
@@ -324,7 +536,8 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests
|
||||
private HistoryOrigin(OpcUaApplicationHost host, string pki, OtOpcUaNodeManager nm, SeriesSource source)
|
||||
{ _host = host; _pki = pki; _nm = nm; Source = source; Port = new OriginHistoryPort(nm); }
|
||||
|
||||
public static async Task<HistoryOrigin> StartAsync(int samples, int maxRawPerRead = 0, int extra = 0)
|
||||
public static async Task<HistoryOrigin> StartAsync(int samples, int maxRawPerRead = 0, int extra = 0, string dataType = "Int32",
|
||||
Func<int, object>? value = null)
|
||||
{
|
||||
var pki = Path.Combine(Path.GetTempPath(), $"h3-origin-{Guid.NewGuid():N}");
|
||||
var started = await OpcUaHostStart.StartAsync(port => new OpcUaApplicationHost(new OpcUaApplicationHostOptions
|
||||
@@ -334,9 +547,9 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests
|
||||
}, NullLogger<OpcUaApplicationHost>.Instance), () => new OtOpcUaSdkServer(), TestContext.Current.CancellationToken);
|
||||
var nm = started.Server.NodeManager!;
|
||||
var source = new SeriesSource(Enumerable.Range(0, samples)
|
||||
.Select(i => new DataValueSnapshot(i, 0, HistoryT0.AddSeconds(i), HistoryT0.AddSeconds(i))).ToArray()) { MaxRawValuesPerRead = maxRawPerRead };
|
||||
.Select(i => new DataValueSnapshot(value?.Invoke(i) ?? i, 0, HistoryT0.AddSeconds(i), HistoryT0.AddSeconds(i))).ToArray()) { MaxRawValuesPerRead = maxRawPerRead };
|
||||
nm.HistorianDataSource = source;
|
||||
nm.EnsureVariable("Plant/Driver/Device/Speed", null, "Speed", "Int32", false, AddressSpaceRealm.Raw, historianTagname: "speed");
|
||||
nm.EnsureVariable("Plant/Driver/Device/Speed", null, "Speed", dataType, false, AddressSpaceRealm.Raw, historianTagname: "speed");
|
||||
nm.EnsureVariable("Plant/Driver/Device/Other", null, "Other", "Int32", false, AddressSpaceRealm.Raw);
|
||||
for (var i = 0; i < extra; i++)
|
||||
nm.EnsureVariable("Plant/Driver/Device/Speed" + i, null, "Speed" + i, "Int32", false, AddressSpaceRealm.Raw, historianTagname: "speed" + i);
|
||||
@@ -381,7 +594,8 @@ public sealed partial class GrpcDataConfiguredDiscoveryWireTests
|
||||
public Task<HistorianRead> ReadAtTimeAsync(string fullReference, IReadOnlyList<DateTime> timestampsUtc, CancellationToken cancellationToken)
|
||||
{
|
||||
Interlocked.Increment(ref _calls);
|
||||
return Task.FromResult(new HistorianRead(timestampsUtc.Select(t => new DataValueSnapshot(1, 0, t, t)).ToList(), null));
|
||||
return Task.FromResult(new HistorianRead(timestampsUtc.Select(t => series.LastOrDefault(s => s.SourceTimestampUtc <= t)
|
||||
?? new DataValueSnapshot(null, 0x809B0000u, t, t)).Select(s => s with { SourceTimestampUtc = s.SourceTimestampUtc }).ToList(), null));
|
||||
}
|
||||
|
||||
public Task<HistoricalEventsResult> ReadEventsAsync(
|
||||
|
||||
Reference in New Issue
Block a user