513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
80 lines
3.3 KiB
C#
80 lines
3.3 KiB
C#
using System.Threading.Channels;
|
|
using Akka.Actor;
|
|
using Akka.TestKit.Xunit2;
|
|
using Google.Protobuf.WellKnownTypes;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Streaming;
|
|
using ZB.MOM.WW.ScadaBridge.Communication.Actors;
|
|
using ZB.MOM.WW.ScadaBridge.Communication.Grpc;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
|
|
|
/// <summary>
|
|
/// Flow Debugger (design 2026-09-05 §5.3/§5.4): <c>AttributeValueUpdate</c> fields 7/8 —
|
|
/// <see cref="StreamRelayActor"/> stamps <c>source_execution_id</c>/<c>trace</c> on the way
|
|
/// out and <see cref="SiteStreamGrpcClient"/> parses them back; an unstamped change (and an
|
|
/// older site's frame) round-trips to null/false.
|
|
/// </summary>
|
|
public class StreamRelayTraceStampTests : TestKit
|
|
{
|
|
private static SiteStreamEvent Relay(AttributeValueChanged change, ActorSystem sys)
|
|
{
|
|
var channel = Channel.CreateUnbounded<SiteStreamEvent>();
|
|
var actor = sys.ActorOf(Props.Create(() => new StreamRelayActor("corr", channel.Writer)));
|
|
actor.Tell(change);
|
|
SiteStreamEvent? evt = null;
|
|
for (var i = 0; i < 40 && !channel.Reader.TryRead(out evt); i++) Thread.Sleep(50);
|
|
Assert.NotNull(evt);
|
|
return evt!;
|
|
}
|
|
|
|
/// <summary>Verifies that a traced change is stamped on the wire and parsed back.</summary>
|
|
[Fact]
|
|
public void TracedChange_IsStampedOnTheWire_AndParsedBack()
|
|
{
|
|
var source = Guid.NewGuid();
|
|
var now = new DateTimeOffset(2026, 9, 5, 12, 0, 0, TimeSpan.Zero);
|
|
var change = new AttributeValueChanged("P1", "Status", "Status", "Running", "Good", now, SourceExecutionId: source, Trace: true);
|
|
|
|
var evt = Relay(change, Sys);
|
|
Assert.Equal(source.ToString("D"), evt.AttributeChanged.SourceExecutionId);
|
|
Assert.True(evt.AttributeChanged.Trace);
|
|
|
|
var back = Assert.IsType<AttributeValueChanged>(SiteStreamGrpcClient.ConvertToDomainEvent(evt));
|
|
Assert.Equal(source, back.SourceExecutionId);
|
|
Assert.True(back.Trace);
|
|
}
|
|
|
|
/// <summary>Verifies that an unstamped change round-trips to null and false.</summary>
|
|
[Fact]
|
|
public void UnstampedChange_RoundTripsToNullAndFalse()
|
|
{
|
|
var change = new AttributeValueChanged("P1", "Status", "Status", "Idle", "Good", DateTimeOffset.UtcNow);
|
|
|
|
var evt = Relay(change, Sys);
|
|
Assert.Equal(string.Empty, evt.AttributeChanged.SourceExecutionId);
|
|
Assert.False(evt.AttributeChanged.Trace);
|
|
|
|
var back = Assert.IsType<AttributeValueChanged>(SiteStreamGrpcClient.ConvertToDomainEvent(evt));
|
|
Assert.Null(back.SourceExecutionId);
|
|
Assert.False(back.Trace);
|
|
}
|
|
|
|
/// <summary>Verifies that an older site frame without the trace fields parses to null and false.</summary>
|
|
[Fact]
|
|
public void OlderSiteFrame_WithoutTheFields_ParsesToNullAndFalse()
|
|
{
|
|
var evt = new SiteStreamEvent
|
|
{
|
|
CorrelationId = "c",
|
|
AttributeChanged = new AttributeValueUpdate
|
|
{
|
|
InstanceUniqueName = "P1", AttributePath = "A", AttributeName = "A", Value = "1",
|
|
Quality = Quality.Good, Timestamp = Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow),
|
|
},
|
|
};
|
|
var back = Assert.IsType<AttributeValueChanged>(SiteStreamGrpcClient.ConvertToDomainEvent(evt));
|
|
Assert.Null(back.SourceExecutionId);
|
|
Assert.False(back.Trace);
|
|
}
|
|
}
|