3c5cbea931
Origin advertises history whenever it has a historian, so a not-ready/demoted endpoint answers HistoryRead Unavailable (ungranted: PermissionDenied) and the consumer fails over like v1 Read instead of 'unsupported'. Client: malformed/undecodable answers are endpoint failures (fresh read moves on); a resumed item is ContinuationPointInvalid while a fresh item of the same batch is BadNoCommunication; a fresh read tries the next endpoint when one lacks history; discovery backoff honoured; origin Cancelled without a caller cancel is BadTimeout (no RecordFailure); caller cancel throws. The deployment lease maps inner/scope faults to BadNoCommunication. The UnaryTimeout cap is documented next to the AdminUI field and in DataConnections.md.
46 lines
3.1 KiB
C#
46 lines
3.1 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>H2 review 3: the deployment lease never lets a history fault escape as an exception.</summary>
|
|
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "H2")]
|
|
public sealed class GrpcDataHistoryLeaseTests
|
|
{
|
|
private static readonly DataView View = new(new("c", "urn:test", "string", "x"), DataRealm.Raw, null, 0, "x");
|
|
|
|
[Fact]
|
|
public async Task A_faulting_inner_connection_is_a_per_item_communication_failure_and_a_caller_cancel_throws()
|
|
{
|
|
var lease = new DataConnectionDeploymentLease(new Faulting(), CancellationToken.None, DataOperationSets.V1 | DataOperations.HistoryRead,
|
|
TimeSpan.FromSeconds(5), 16, 16, 1 << 20, 4, 16, 1 << 20, () => true, () => { });
|
|
var request = new DataHistoryReadRequest(new DataHistoryRawDetails(null, DateTimeOffset.UnixEpoch, 1, false), [new("a", View)],
|
|
new DataBudget(TimeSpan.FromSeconds(5), 16, 1 << 20));
|
|
(await lease.ReadHistoryAsync(request, TestContext.Current.CancellationToken)).Single().StatusCode.ShouldBe(0x80310000u);
|
|
using var cancelled = new CancellationTokenSource();
|
|
await cancelled.CancelAsync();
|
|
await Should.ThrowAsync<OperationCanceledException>(() => lease.ReadHistoryAsync(request, cancelled.Token));
|
|
}
|
|
|
|
private sealed class Faulting : IDataConnection, IDataHistoryService
|
|
{
|
|
public DataTarget Target { get; } = new(DataTargetMode.Node, "c", "a");
|
|
public TimeProvider Clock => TimeProvider.System;
|
|
public Task<IReadOnlyList<DataHistoryReadResult>> ReadAsync(DataHistoryReadRequest request, CancellationToken cancellationToken)
|
|
{
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
throw new InvalidOperationException("No ready authenticated data endpoint.");
|
|
}
|
|
public Task ReleaseAsync(IReadOnlyList<byte[]> continuations, CancellationToken cancellationToken) => 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();
|
|
Task<IReadOnlyList<ReadResult>> IDataReadService.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;
|
|
}
|
|
}
|