348ffaec1c
OnSnapshotChanged used to re-project every cluster group and re-render the whole page for each driver publish, per open tab. It now only marks a CoalescingDirtyFlag; the 5 s tick rebuilds when the flag is set or the config load changed (or evicted) anything. Refs #745 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.AdminUI.Hosts;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Hosts;
|
|
|
|
/// <summary>
|
|
/// R04 P4: a driver health publish only marks <c>/hosts</c> dirty; the page's 5 s tick rebuilds and
|
|
/// renders at most once, however many publishes arrived.
|
|
/// </summary>
|
|
[Trait("Category", "Unit")]
|
|
public sealed class HostsRenderCoalescingTests
|
|
{
|
|
[Fact]
|
|
public void Many_marks_coalesce_into_one_consume()
|
|
{
|
|
var flag = new CoalescingDirtyFlag();
|
|
for (var i = 0; i < 200; i++) flag.Mark();
|
|
|
|
flag.TryConsume().ShouldBeTrue();
|
|
flag.TryConsume().ShouldBeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void A_fresh_flag_is_clean_and_a_mark_after_consume_is_seen()
|
|
{
|
|
var flag = new CoalescingDirtyFlag();
|
|
flag.TryConsume().ShouldBeFalse();
|
|
|
|
// Positive control: the flag is not stuck clean.
|
|
flag.Mark();
|
|
flag.TryConsume().ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Concurrent_marks_are_never_lost()
|
|
{
|
|
var flag = new CoalescingDirtyFlag();
|
|
Parallel.For(0, 1000, _ => flag.Mark());
|
|
|
|
flag.TryConsume().ShouldBeTrue();
|
|
}
|
|
|
|
/// <summary>Source pin (no bUnit): the snapshot handler must not render or rebuild.</summary>
|
|
[Fact]
|
|
public void Snapshot_handler_only_marks_and_the_tick_consumes()
|
|
{
|
|
var src = AdminUiSource.Read("Components", "Pages", "Hosts.razor");
|
|
|
|
src.ShouldContain("private void OnSnapshotChanged(DriverHealthChanged _) => _driversDirty.Mark();");
|
|
src.ShouldContain("if (_driversDirty.TryConsume() | configChanged) RebuildDriverGroups();");
|
|
}
|
|
}
|