2470f82eea
v2-ci / unit-tests (push) Has been cancelled
Owner decision 2026-11-13 on #872 item 1. StatusCodeMap.FromMxStatus now maps a Pending or Warning row to Uncertain (0x40000000) for any detail, ahead of the detail vocabulary, keeping the once-per-(detail, category) warning. MXAccess sets success = -1 on Pending (accepted, in progress); neither category is a failure. Detail 8001 (automation-object ConfigurationError, write rejected for type conversion, live-captured on windev 2026-11-13) maps to BadTypeMismatch. 8018 stays BadUserAccessDenied via its SecurityError category, now pinned by a test. Data change: the value is published Uncertain. Write reply: the result is Uncertain, never Good, so the server (which commits only Good) reports the write not committed and reverts the node; a later MXAccess commit arrives as a data change. Host status is unchanged (probe decode treats Uncertain and Bad alike, quality < 192 -> Unknown); no alarm path calls the map. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
97 lines
4.3 KiB
C#
97 lines
4.3 KiB
C#
using System.Runtime.CompilerServices;
|
|
using System.Threading.Channels;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Runtime;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Tests.Runtime;
|
|
|
|
/// <summary>
|
|
/// #866 review: the gateway fills <c>Statuses</c> on every data change, and the pump used the status row
|
|
/// whenever one was present, so the item's OPC DA quality was never read. An off-scan / Bad / Uncertain
|
|
/// attribute carrying an OK status row was published Good. A failure status row still wins.
|
|
/// </summary>
|
|
public sealed class EventPumpQualityTests
|
|
{
|
|
private const int WaitMs = 10_000;
|
|
|
|
private static MxStatusProxy Ok => new() { Success = 1, Category = MxStatusCategory.Ok };
|
|
|
|
private sealed class ChannelSubscriber : IGalaxySubscriber
|
|
{
|
|
private readonly Channel<MxEvent> _events = Channel.CreateUnbounded<MxEvent>();
|
|
|
|
public Task<IReadOnlyList<SubscribeResult>> SubscribeBulkAsync(
|
|
IReadOnlyList<string> fullReferences, int bufferedUpdateIntervalMs, CancellationToken cancellationToken)
|
|
=> Task.FromResult<IReadOnlyList<SubscribeResult>>([]);
|
|
|
|
public Task UnsubscribeBulkAsync(IReadOnlyList<int> itemHandles, CancellationToken cancellationToken) => Task.CompletedTask;
|
|
|
|
public async IAsyncEnumerable<MxEvent> StreamEventsAsync([EnumeratorCancellation] CancellationToken cancellationToken)
|
|
{
|
|
await foreach (var ev in _events.Reader.ReadAllAsync(cancellationToken).ConfigureAwait(false))
|
|
yield return ev;
|
|
}
|
|
|
|
public ValueTask EmitAsync(int handle, int quality, MxStatusProxy status)
|
|
{
|
|
var ev = new MxEvent
|
|
{
|
|
Family = MxEventFamily.OnDataChange,
|
|
ItemHandle = handle,
|
|
Value = new MxValue { DoubleValue = 1 },
|
|
Quality = quality,
|
|
SourceTimestamp = Timestamp.FromDateTime(DateTime.UtcNow),
|
|
};
|
|
ev.Statuses.Add(status);
|
|
return _events.Writer.WriteAsync(ev);
|
|
}
|
|
}
|
|
|
|
private static async Task<uint> PublishedStatusAsync(int quality, MxStatusProxy status)
|
|
{
|
|
var subscriber = new ChannelSubscriber();
|
|
var registry = new SubscriptionRegistry();
|
|
registry.Register(1, [new TagBinding("Tank01.Level", 7)]);
|
|
var delivered = new TaskCompletionSource<DataChangeEventArgs>(TaskCreationOptions.RunContinuationsAsynchronously);
|
|
|
|
await using var pump = new EventPump(subscriber, registry, channelCapacity: 4, clientName: "Quality");
|
|
pump.OnDataChange += (_, e) => delivered.TrySetResult(e);
|
|
pump.Start();
|
|
|
|
await subscriber.EmitAsync(7, quality, status);
|
|
(await Task.WhenAny(delivered.Task, Task.Delay(WaitMs, TestContext.Current.CancellationToken))).ShouldBe(delivered.Task);
|
|
return (await delivered.Task).Snapshot.StatusCode;
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(192, 0x00000000u)] // Good
|
|
[InlineData(24, 0x808D0000u)] // Bad OutOfService (off scan)
|
|
[InlineData(8, 0x808A0000u)] // Bad NotConnected
|
|
[InlineData(68, 0x40900000u)] // Uncertain LastUsableValue
|
|
public async Task An_ok_status_row_is_graded_by_the_item_quality(int quality, uint expected)
|
|
=> (await PublishedStatusAsync(quality, Ok)).ShouldBe(expected);
|
|
|
|
/// <summary>#872: a Pending or Warning status row on a data change publishes the value Uncertain, not Bad.</summary>
|
|
[Theory]
|
|
[InlineData(MxStatusCategory.Pending, -1, 0)]
|
|
[InlineData(MxStatusCategory.Pending, -1, 1007)]
|
|
[InlineData(MxStatusCategory.Warning, 0, 0)]
|
|
[InlineData(MxStatusCategory.Warning, 0, 2)]
|
|
public async Task A_pending_or_warning_status_row_publishes_uncertain(MxStatusCategory category, int success, int detail)
|
|
{
|
|
var row = new MxStatusProxy { Success = success, Category = category, Detail = detail };
|
|
(await PublishedStatusAsync(192, row)).ShouldBe(StatusCodeMap.Uncertain);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task A_failure_status_row_wins_over_a_good_quality()
|
|
{
|
|
var failure = new MxStatusProxy { Success = 0, Category = MxStatusCategory.CommunicationError, Detail = 2 };
|
|
(await PublishedStatusAsync(192, failure)).ShouldBe(StatusCodeMap.BadCommunicationError);
|
|
}
|
|
}
|