f1b23abcb4
- b: ProjectedHistoryAccess releases the prior origin cursor on any Bad answer to a resumed node (and on a mismatched answer) — an unsent refusal left it open at the origin; idempotent. - c: DataConnectionDeploymentLease, when its scope moves while a history answer is in flight, releases the dropped answer's new continuations (best effort); resumed items are BadContinuationPointInvalid, fresh ones BadNoCommunication. - d: ProjectedHistoryRead: a throw while serving outcome i (FromClr on an unconvertible value, a store fault) releases outcome i's cursor unless the store already owns it, and every later outcome's. Each red on revert (mutation).
67 lines
4.0 KiB
C#
67 lines
4.0 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
|
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
|
|
|
|
/// <summary>
|
|
/// H3 review round 3 nit (c): the deployment lease drops a history answer when its scope moves while the answer is in flight —
|
|
/// the new origin continuations that answer carries are released (not stranded), and a resumed item is
|
|
/// <c>BadContinuationPointInvalid</c> (its token cannot be presented again), a fresh one <c>BadNoCommunication</c>.
|
|
/// </summary>
|
|
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H3")]
|
|
public sealed class GrpcDataDeployedHistoryLeaseTests
|
|
{
|
|
private static readonly DataView View = new(new("c", "urn:test", "string", "x"), DataRealm.Raw, null, 0, "x");
|
|
|
|
[Fact]
|
|
public async Task A_scope_move_during_the_answer_releases_its_new_continuations()
|
|
{
|
|
var current = true;
|
|
var inner = new Inner { OnRead = () => current = false };
|
|
var lease = new DataConnectionDeploymentLease(inner, CancellationToken.None, DataOperations.HistoryRead, TimeSpan.FromSeconds(5),
|
|
16, 16, 1 << 20, 1, 1, 1 << 20, () => current, () => { });
|
|
var request = new DataHistoryReadRequest(new DataHistoryRawDetails(null, DateTimeOffset.UnixEpoch.AddDays(1), 2, false),
|
|
[new("fresh", View), new("resumed", View, null, [1])], new DataBudget(TimeSpan.FromSeconds(5), 16, 1 << 20));
|
|
var results = await lease.ReadHistoryAsync(request, TestContext.Current.CancellationToken);
|
|
results[0].StatusCode.ShouldBe(0x80310000u);
|
|
results[1].StatusCode.ShouldBe(0x804A0000u);
|
|
var deadline = DateTime.UtcNow.AddSeconds(5);
|
|
while (inner.ReleasedCount == 0 && DateTime.UtcNow < deadline) await Task.Delay(10, TestContext.Current.CancellationToken);
|
|
inner.Released.ShouldBe([[8], [9]], ignoreOrder: true);
|
|
}
|
|
|
|
private sealed class Inner : IDataConnection, IDataHistoryService
|
|
{
|
|
public Action OnRead { get; init; } = () => { };
|
|
private readonly List<byte[]> _released = [];
|
|
public int ReleasedCount { get { lock (_released) return _released.Count; } }
|
|
public byte[][] Released { get { lock (_released) return _released.ToArray(); } }
|
|
public DataTarget Target => new(DataTargetMode.Cluster, "c", null);
|
|
public TimeProvider Clock => TimeProvider.System;
|
|
|
|
public Task<IReadOnlyList<DataHistoryReadResult>> ReadAsync(DataHistoryReadRequest request, CancellationToken cancellationToken)
|
|
{
|
|
OnRead();
|
|
byte k = 8;
|
|
return Task.FromResult<IReadOnlyList<DataHistoryReadResult>>(request.Items
|
|
.Select(i => new DataHistoryReadResult(i.CorrelationId, 0, [], [k++])).ToArray());
|
|
}
|
|
|
|
public Task ReleaseAsync(IReadOnlyList<byte[]> continuations, CancellationToken cancellationToken)
|
|
{
|
|
lock (_released) _released.AddRange(continuations);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task<DataCapabilities> GetCapabilitiesAsync(DataBudget budget, CancellationToken cancellationToken) => throw new NotSupportedException();
|
|
public Task<DataBrowseBranch> BrowseAsync(BrowseRequest request, CancellationToken cancellationToken) => throw new NotSupportedException();
|
|
public Task<IReadOnlyList<DataItemResult<DataMetadata>>> GetMetadataAsync(MetadataRequest request, CancellationToken cancellationToken) => throw new NotSupportedException();
|
|
public Task<IReadOnlyList<ReadResult>> ReadAsync(ReadRequest request, CancellationToken cancellationToken) => throw new NotSupportedException();
|
|
public Task<IReadOnlyList<WriteItemResult>> WriteAsync(WriteBatch request, CancellationToken cancellationToken) => throw new NotSupportedException();
|
|
public Task<IDataSubscription> SubscribeAsync(CancellationToken cancellationToken) => throw new NotSupportedException();
|
|
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
|
}
|
|
}
|