test(worker): watch-list update rebuilds the whole subtag standby for a one-alarm change (MXA-010, #258)
ci / windows-x86 (push) Failing after 2m21s
ci / java (push) Failing after 15m7s
ci / portable (push) Failing after 19m6s

Reproducer: currently fails — the update builds a second source, re-advises all
102 subtags on it and disposes the first.
This commit is contained in:
Joseph Doherty
2026-12-03 13:04:58 -05:00
parent 6804341152
commit d8553b1ff7
@@ -644,6 +644,52 @@ public sealed class AlarmCommandHandlerTests
Assert.Equal("33.AckMsg", AckItemOf(handler));
}
/// <summary>
/// MXA-010: adding one alarm to a fallback watch list advises only that alarm's subtags on
/// the existing subtag source. Rebuilding the standby instead created a second source (a
/// second MXAccess server registration), re-advised every watched subtag on it, and
/// unregistered the first — work proportional to the whole watch list for a one-item change.
/// </summary>
[Fact]
public void UpdateWatchList_OneTargetAdded_AdvisesOnlyTheAddedSubtagsOnTheExistingSource()
{
List<CountingSubtagSource> sources = new List<CountingSubtagSource>();
AlarmCommandHandler handler = new AlarmCommandHandler(
new MxAccessEventQueue(),
() => new FakeConsumer(),
threadAffinityCheck: null,
comFactory: null,
standbyFactory: watchList =>
{
CountingSubtagSource source = new CountingSubtagSource();
sources.Add(source);
return new SubtagAlarmConsumer(source, watchList);
},
ackWriterFactory: () => new RecordingAckWriter());
SubscribeAlarmsCommand subscribe = new SubscribeAlarmsCommand
{
SubscriptionExpression = @"\\HOST\Galaxy!Area",
FallbackEnabled = true,
};
List<AlarmSubtagTarget> watchList = new List<AlarmSubtagTarget>();
for (int i = 0; i < 50; i++)
{
watchList.Add(NewTarget($"Galaxy!Area.Tank{i:D2}.Alarm"));
}
subscribe.WatchList.AddRange(watchList);
handler.Subscribe(subscribe, "s1");
Assert.Single(sources);
Assert.Equal(100, sources[0].AdvisedCount);
watchList.Add(NewTarget("Galaxy!Area.Tank50.Alarm"));
handler.UpdateWatchList(watchList);
Assert.Single(sources);
Assert.False(sources[0].Disposed);
Assert.Equal(102, sources[0].AdvisedCount);
}
/// <summary>
/// A non-failover subscribe (alarmmgr-only) never enqueues a
/// provider-mode-changed event, and a subsequent Unsubscribe detaches
@@ -793,6 +839,39 @@ public sealed class AlarmCommandHandlerTests
}
}
/// <summary>Subtag source that counts the addresses it is asked to advise.</summary>
private sealed class CountingSubtagSource : ISubtagAlarmSource
{
#pragma warning disable CS0067 // Event never invoked — these tests count advise work, not transitions.
/// <inheritdoc />
public event EventHandler<SubtagValueChange>? ValueChanged;
#pragma warning restore CS0067
/// <summary>Gets the addresses currently advised.</summary>
public HashSet<string> Advised { get; } = new HashSet<string>(StringComparer.Ordinal);
/// <summary>Gets the total number of advise operations performed (AddItem + Advise pairs).</summary>
public int AdvisedCount { get; private set; }
/// <summary>Gets a value indicating whether the source was disposed.</summary>
public bool Disposed { get; private set; }
/// <inheritdoc />
public void Advise(IReadOnlyCollection<string> itemAddresses)
{
foreach (string address in itemAddresses)
{
if (Advised.Add(address))
{
AdvisedCount++;
}
}
}
/// <inheritdoc />
public void Dispose() => Disposed = true;
}
private sealed class RecordingAckWriter : IAlarmAckWriter
{
public string? LastItemAddress { get; private set; }