Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.AdminUI.Tests/InProcessBroadcasterTests.cs
T
Joseph Doherty 61193629b6
v2-ci / build (push) Failing after 36s
v2-ci / unit-tests (tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.ControlPlane.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests) (push) Has been skipped
v2-ci / unit-tests (tests/Server/ZB.MOM.WW.OtOpcUa.Security.Tests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.Host.IntegrationTests) (push) Has been skipped
v2-ci / integration (tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests) (push) Has been skipped
fix(adminui): wire Test Connect probes + live panels on admin-only nodes
Both bugs surfaced only on split-role deployments (the MAIN cluster's
admin-only nodes), where the AdminUI runs without the driver role.

- Test Connect returned "No probe registered" for every driver: the
  IDriverProbe set was registered only under the driver role, but the
  admin-operations singleton that consumes it is pinned to admin. Extract
  AddOtOpcUaDriverProbes() (idempotent via TryAddEnumerable) and call it
  in the hasAdmin path too.

- Live driver-status/alerts/script-log panels showed "SignalR error:
  Connection refused": these Blazor Server components opened a HubConnection
  to their own hub via the browser's public URL, which server-side code
  can't reach behind Traefik (host :9200 -> container :9000). Read the
  in-process source directly instead -- DriverStatus via
  IDriverStatusSnapshotStore.SnapshotChanged, Alerts/ScriptLog via a new
  IInProcessBroadcaster<T>. Fleet status was unaffected (reads DB/ActorSystem).

Adds unit tests for probe registration, the snapshot-store event, and the
broadcaster.
2026-05-29 16:38:32 -04:00

52 lines
1.6 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.Hubs;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests;
/// <summary>
/// Covers the in-process fan-out the Blazor Server Alerts / Script log pages rely on:
/// <see cref="IInProcessBroadcaster{T}.Publish"/> raises <c>Received</c> for every current
/// subscriber, and unsubscribing stops delivery. These pages read this broadcaster directly
/// instead of opening a self-targeted SignalR connection (unreachable behind a reverse proxy).
/// </summary>
public sealed class InProcessBroadcasterTests
{
[Fact]
public void Publish_raises_Received_for_all_current_subscribers()
{
var broadcaster = new InProcessBroadcaster<string>();
var a = new List<string>();
var b = new List<string>();
broadcaster.Received += a.Add;
broadcaster.Received += b.Add;
broadcaster.Publish("evt-1");
a.ShouldBe(["evt-1"]);
b.ShouldBe(["evt-1"]);
}
[Fact]
public void Unsubscribed_handler_stops_receiving()
{
var broadcaster = new InProcessBroadcaster<string>();
var received = new List<string>();
void Handler(string s) => received.Add(s);
broadcaster.Received += Handler;
broadcaster.Publish("first");
broadcaster.Received -= Handler;
broadcaster.Publish("second");
received.ShouldBe(["first"]);
}
[Fact]
public void Publish_with_no_subscribers_does_not_throw()
{
var broadcaster = new InProcessBroadcaster<int>();
Should.NotThrow(() => broadcaster.Publish(42));
}
}