feat(streaming): carry IsMesReportable on AlarmStateUpdate (25) and DebugAlarmStateDto (20) (ScadaBridge#60)
Central's Debug View live stream and Alarm Summary cache always saw false because neither wire message had the field. Additive proto fields, vendored C# regenerated with docker/regen-proto.sh (sitestream + sitecommand), mapped both ways in StreamRelayActor/SiteStreamGrpcClient and SiteCommandDtoMapper. The live stream publishes Alarm Actor events, which never carried the flag, so InstanceActor.HandleAlarmStateChanged now stamps it before retaining and publishing. A pre-#60 site sends the proto3 default. No UI badge yet. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+40
-3
@@ -8,16 +8,18 @@ using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
|
||||
using ZB.MOM.WW.ScadaBridge.SiteRuntime;
|
||||
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Actors;
|
||||
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Persistence;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Streaming;
|
||||
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
|
||||
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Streaming;
|
||||
using ZB.MOM.WW.ScadaBridge.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Actors;
|
||||
|
||||
/// <summary>
|
||||
/// The deployed alarm's <c>IsMesReportable</c> flag must reach the site-local alarm
|
||||
/// snapshot that <c>Alarms.CurrentAsync()</c> and the Debug View query both build (the
|
||||
/// flag does not cross <c>DebugAlarmStateDto</c> to central in this slice). It is stamped in ONE
|
||||
/// place — <c>BuildAlarmStatesSnapshot</c> — so a computed alarm that has fired (served
|
||||
/// snapshot that <c>Alarms.CurrentAsync()</c> and the Debug View query both build, and the
|
||||
/// events published to the site stream (Gitea #60). The snapshot projection stamps every
|
||||
/// row in <c>BuildAlarmStatesSnapshot</c>, so a computed alarm that has fired (served
|
||||
/// from the retained <c>AlarmStateChanged</c>) and one that never has (served from the
|
||||
/// bare Normal fallback) can never disagree about the flag.
|
||||
/// </summary>
|
||||
@@ -154,6 +156,41 @@ public class InstanceActorMesReportableSnapshotTests : TestKit, IDisposable
|
||||
Assert.False(Assert.Single(snapshot.Alarms, a => a.AlarmName == "TempSpike").IsMesReportable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the event the Instance Actor publishes to the site stream — the one the
|
||||
/// Debug View live feed and central's Alarm Summary cache consume — carries the deployed
|
||||
/// MES-reportable flag, not only the snapshot (Gitea #60).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void PublishedAlarmEvent_CarriesIsMesReportable()
|
||||
{
|
||||
const string instance = "Oven3";
|
||||
var streamManager = new SiteStreamManager(_options, NullLogger<SiteStreamManager>.Instance);
|
||||
streamManager.Initialize(Sys);
|
||||
var subscriber = CreateTestProbe();
|
||||
streamManager.Subscribe(instance, subscriber.Ref);
|
||||
|
||||
var actor = ActorOf(Props.Create(() => new InstanceActor(
|
||||
instance,
|
||||
JsonSerializer.Serialize(TwoComputedAlarmsConfig(instance)),
|
||||
_storage,
|
||||
_compilationService,
|
||||
_sharedScriptLibrary,
|
||||
streamManager,
|
||||
_options,
|
||||
NullLogger<InstanceActor>.Instance,
|
||||
null)));
|
||||
|
||||
actor.Tell(new SetStaticAttributeCommand(
|
||||
"corr-temp", instance, "Temperature", "90", DateTimeOffset.UtcNow));
|
||||
Assert.True(ExpectMsg<SetStaticAttributeResponse>(TimeSpan.FromSeconds(5)).Success);
|
||||
|
||||
var published = subscriber.FishForMessage<AlarmStateChanged>(
|
||||
m => m.AlarmName == "HighTemp" && m.State == AlarmState.Active,
|
||||
TimeSpan.FromSeconds(5));
|
||||
Assert.True(published.IsMesReportable);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user