fix(grpc-data): A1 review round 2 F4 — a Galaxy sentinel signals only a stream opened under the live subscription
The feed raises a new IGalaxyAlarmFeed.StreamOpened (default no-op accessors) before each stream's first message; GalaxyDriver records the live subscription then, and its sentinel signals only if that is still the live one — so refs whose snapshot entries arrived before (or without) the subscription are never signalled. The handle is now added before the feed starts, so the first stream opens under it.
This commit is contained in:
+35
@@ -88,6 +88,41 @@ public sealed class GalaxyInitialAlarmStateSignalTests
|
||||
trace.ShouldBe(["signal:" + Tank1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Review round 2 F4: a stream whose snapshot entries arrived while no subscription was live (they were dropped)
|
||||
/// must not signal at its sentinel just because a subscription is live by then — the signal would cover refs whose
|
||||
/// state never reached the host. The next stream, opened under the live subscription, signals.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task A_sentinel_for_a_stream_opened_under_an_earlier_subscription_does_not_signal()
|
||||
{
|
||||
await using var streams = new ScriptedStreams();
|
||||
using var driver = NewDriver(streams.Feed);
|
||||
var trace = Record(driver);
|
||||
|
||||
var first = await driver.SubscribeAlarmsAsync([Tank1], Ct);
|
||||
var s = await streams.NextAsync();
|
||||
await driver.UnsubscribeAlarmsAsync(first, Ct);
|
||||
var sentinelSeen = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var entryHandled = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
streams.Feed.OnAlarmTransition += (_, _) => entryHandled.TrySetResult();
|
||||
await s.WriteAsync(Snapshot(Tank1, AlarmConditionState.Active), Ct); // dropped: nothing is subscribed
|
||||
await entryHandled.Task.WaitAsync(TimeSpan.FromSeconds(10), Ct);
|
||||
await driver.SubscribeAlarmsAsync([Tank1], Ct); // live again BEFORE the sentinel
|
||||
streams.Feed.SnapshotDelivered += (_, _) => sentinelSeen.TrySetResult();
|
||||
await s.WriteAsync(new AlarmFeedMessage { SnapshotComplete = true }, Ct);
|
||||
await sentinelSeen.Task.WaitAsync(TimeSpan.FromSeconds(10), Ct);
|
||||
trace.ShouldBeEmpty();
|
||||
|
||||
// Positive control: the next stream opens under the live subscription and its sentinel signals.
|
||||
s.Complete(new InvalidOperationException("reopen"));
|
||||
var s2 = await streams.NextAsync();
|
||||
await s2.WriteAsync(Snapshot(Tank1, AlarmConditionState.Active), Ct);
|
||||
await s2.WriteAsync(new AlarmFeedMessage { SnapshotComplete = true }, Ct);
|
||||
await TestWait.UntilAsync(() => trace.Count >= 2, "the reopened stream's event and signal", () => Dump(trace));
|
||||
trace.ShouldBe(["event:" + Tank1, "signal:" + Tank1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// (vii) a stream reopen re-signals; a deploy that adds a condition (re-subscribe with the larger set) is
|
||||
/// covered by the NEXT sentinel, not before it.
|
||||
|
||||
Reference in New Issue
Block a user