Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcData1057SnapshotValidityTests.cs
T
Joseph Doherty 7436e1af95 fix(grpc-data): #1057 a sibling source's invalidation no longer resets an in-flight snapshot on the same partition
#994 (R-9) taught the interest lease to tell its own sources' invalidation from a sibling's, but SnapshotLease still
compared the partition-wide control stamp, so any sibling invalidation, status barrier or plain lock contention reset
the snapshot and with it the stream. Each snapshot cursor now adopts a newer stamp once it proves none of ITS captured
sources moved (quiet version, invalidation version, binding/fence/gate retirement, same source state), read inside a
captured control window; an in-progress bracket is spun on briefly. Own-source invalidation, a partition-wide epoch bump,
a poisoned signal and history roll-off still reset.
2026-12-03 15:13:31 -05:00

84 lines
4.0 KiB
C#

using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
/// <summary>
/// #1057: #994 (R-9) made an interest lease tell its own sources' invalidation from a sibling's, but the snapshot lease still
/// compared the partition-wide control stamp, so any sibling invalidation (including plain lock contention) reset an in-flight
/// snapshot — and with it the stream ("Snapshot catch-up expired; retry later.").
/// </summary>
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Issue", "1057")]
public sealed class GrpcData1057SnapshotValidityTests
{
[Fact]
public void A_sibling_sources_invalidation_does_not_reset_an_in_flight_snapshot_of_the_same_partition()
{
using var hub = HubTest.Create(partitions: 1, bytes: 1_000_000, ingress: 100, dirty: 100);
var mine = HubTest.Ticket("driver", "mine");
var sibling = HubTest.Ticket("driver", "sibling");
HubTest.BindAndPublish(hub, mine, 1, 1);
HubTest.BindAndPublish(hub, sibling, 1, 1);
hub.ProcessPending();
hub.TryCaptureInterestSnapshot([mine], HubTest.Budget, CancellationToken.None, out var snapshot, out var interest).ShouldBeTrue();
using (snapshot!) using (interest!)
{
hub.Invalidate(sibling, "source serialization contention");
snapshot!.IsReset.ShouldBeFalse("a sibling's invalidation is not this snapshot's");
snapshot.IsItemCurrent(mine).ShouldBeTrue();
// A sibling STATUS change (an outer-control bracket, no quiet bump) is not this snapshot's either.
hub.TryPublishStatus(sibling, 2, 0x80000000u, null, null).ShouldBeTrue();
hub.ProcessPending();
snapshot.IsReset.ShouldBeFalse();
snapshot.IsItemCurrent(mine).ShouldBeTrue();
// Positive control: this snapshot's OWN source's invalidation still resets it.
hub.Invalidate(mine, "contention");
snapshot.IsReset.ShouldBeTrue();
}
}
[Fact]
public void An_own_source_status_change_still_invalidates_its_snapshot_item()
{
using var hub = HubTest.Create(partitions: 1, bytes: 1_000_000, ingress: 100, dirty: 100);
var mine = HubTest.Ticket("driver", "mine");
var sibling = HubTest.Ticket("driver", "sibling");
HubTest.BindAndPublish(hub, mine, 1, 1);
HubTest.BindAndPublish(hub, sibling, 1, 1);
hub.ProcessPending();
hub.TryCaptureSnapshot([mine, sibling], HubTest.Budget, CancellationToken.None, out var snapshot).ShouldBeTrue();
using (snapshot!)
{
hub.TryPublishStatus(mine, 2, 0x80000000u, null, null).ShouldBeTrue();
snapshot!.IsItemCurrent(mine).ShouldBeFalse("its captured value was invalidated by a status change");
}
}
[Fact]
public void A_partition_wide_invalidation_and_a_retired_binding_still_reset_the_snapshot()
{
using var hub = HubTest.Create(partitions: 1, bytes: 1_000_000, ingress: 100, dirty: 100);
var mine = HubTest.Ticket("driver", "mine");
HubTest.BindAndPublish(hub, mine, 1, 1);
hub.ProcessPending();
hub.TryCaptureSnapshot([mine], HubTest.Budget, CancellationToken.None, out var first).ShouldBeTrue();
using (first!)
{
hub.InvalidatePartitionFor(mine.Key, "partition overflow");
first!.IsReset.ShouldBeTrue();
}
using var other = HubTest.Create(partitions: 1, bytes: 1_000_000, ingress: 100, dirty: 100);
var bound = HubTest.Ticket("driver", "bound");
HubTest.BindAndPublish(other, bound, 1, 1);
other.ProcessPending();
other.TryCaptureSnapshot([bound], HubTest.Budget, CancellationToken.None, out var second).ShouldBeTrue();
using (second!)
{
var newer = new SourceTicket(bound.Key, new(1, 2));
other.TryBind(newer).ShouldBeTrue(); // retires the captured binding
second!.IsReset.ShouldBeTrue();
}
}
}