server(alarms): provider-mode gauge startup baseline; reconcile-lock comment; de-flake monitor test

This commit is contained in:
Joseph Doherty
2026-06-13 10:29:13 -04:00
parent ee459f43e1
commit bcc54ca56b
3 changed files with 31 additions and 3 deletions
@@ -56,8 +56,11 @@ public sealed class GatewayAlarmMonitorProviderModeTests
await monitor.StartAsync(cts.Token);
await sessions.WaitForSubscribeAsync(WaitTimeout);
// Subscribe a live feed reader, drain its first (provider status) message.
// Subscribe a live feed reader. Gate emitting the mode-change event until the
// reader has consumed its baseline ProviderStatus message, avoiding a race where
// the event arrives before the subscriber is registered and draining its snapshot.
List<AlarmFeedMessage> received = [];
TaskCompletionSource baselineReceived = new(TaskCreationOptions.RunContinuationsAsynchronously);
using CancellationTokenSource streamCts = new();
Task reader = Task.Run(async () =>
{
@@ -65,7 +68,15 @@ public sealed class GatewayAlarmMonitorProviderModeTests
{
await foreach (AlarmFeedMessage message in monitor.StreamAsync(null, streamCts.Token))
{
lock (received) { received.Add(message); }
lock (received)
{
received.Add(message);
// Signal once the first message (baseline ProviderStatus) has arrived.
if (received.Count == 1)
{
baselineReceived.TrySetResult();
}
}
}
}
catch (OperationCanceledException)
@@ -74,10 +85,13 @@ public sealed class GatewayAlarmMonitorProviderModeTests
}
});
// Wait for the baseline ProviderStatus to arrive before emitting the mode change,
// so the subscriber is registered and the event is not dropped.
await baselineReceived.Task.WaitAsync(WaitTimeout);
// Emit the worker event that flips the provider into subtag mode.
sessions.EmitEvent(new MxEvent
{
Family = MxEventFamily.OnAlarmProviderModeChanged,
OnAlarmProviderModeChanged = new OnAlarmProviderModeChangedEvent
{
Mode = AlarmProviderMode.Subtag,