Resolve all high-severity architecture review findings
This commit is contained in:
+24
@@ -26,6 +26,30 @@ public class MxGatewayBatchSeamTests
|
||||
["ReadTimeoutMs"] = "2000",
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public async Task UnsubscribeOldHandle_PreservesNewHandleRouting(bool batch)
|
||||
{
|
||||
var fake = new FakeMxGatewayClient();
|
||||
await using var adapter = NewAdapter(fake);
|
||||
await adapter.ConnectAsync(Details());
|
||||
var received = new List<object?>();
|
||||
var old = await adapter.SubscribeAsync("A.x", (_, value) => received.Add(value.Value));
|
||||
await adapter.SubscribeAsync("A.x", (_, value) => received.Add(value.Value));
|
||||
if (batch) await adapter.UnsubscribeBatchAsync([old]);
|
||||
else await adapter.UnsubscribeAsync(old);
|
||||
await WaitUntilAsync(() => fake.OnUpdate != null);
|
||||
fake.OnUpdate!(new MxValueUpdate("A.x", 7, QualityCode.Good, DateTimeOffset.UtcNow));
|
||||
Assert.Equal([7], received);
|
||||
}
|
||||
|
||||
private static async Task WaitUntilAsync(Func<bool> condition)
|
||||
{
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(2));
|
||||
while (!condition()) await Task.Delay(10, timeout.Token);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SubscribeBatch_IssuesExactlyOneBulkCallPerBatch()
|
||||
{
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using System.Reflection;
|
||||
using Opc.Ua;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Alarms;
|
||||
using ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Adapters;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests.Adapters;
|
||||
|
||||
public class RealOpcUaSnapshotScopeTests
|
||||
{
|
||||
[Fact]
|
||||
public void RefreshBoundaries_PreserveSourceAndHaveDistinctEpochs()
|
||||
{
|
||||
var client = new RealOpcUaClient();
|
||||
var events = new List<NativeAlarmTransition>();
|
||||
var handler = typeof(RealOpcUaClient).GetMethod("HandleAlarmEvent", BindingFlags.Instance | BindingFlags.NonPublic)!;
|
||||
void Emit(string handle, string source, NodeId type) => handler.Invoke(client,
|
||||
[handle, source, new EventFieldList { EventFields = new VariantCollection { new(type), new(), new(), new(), new(), new() } }, (Action<NativeAlarmTransition>)events.Add]);
|
||||
Emit("a", "A", ObjectTypeIds.RefreshStartEventType);
|
||||
Emit("b", "B", ObjectTypeIds.RefreshStartEventType);
|
||||
Emit("a", "A", ObjectTypeIds.RefreshEndEventType);
|
||||
Emit("b", "B", ObjectTypeIds.RefreshEndEventType);
|
||||
Assert.Equal(4, events.Count);
|
||||
Assert.Equal(["SnapshotStart", "SnapshotStart", "SnapshotComplete", "SnapshotComplete"], events.Select(e => e.Kind.ToString()));
|
||||
Assert.Equal(["A", "B", "A", "B"], events.Select(e => e.SourceObjectReference));
|
||||
var epoch = typeof(NativeAlarmTransition).GetProperty("SnapshotId")!;
|
||||
Assert.NotNull(epoch);
|
||||
Assert.NotNull(epoch.GetValue(events[0]));
|
||||
Assert.Equal(epoch.GetValue(events[0]), epoch.GetValue(events[2]));
|
||||
Assert.Equal(epoch.GetValue(events[1]), epoch.GetValue(events[3]));
|
||||
Assert.NotEqual(epoch.GetValue(events[0]), epoch.GetValue(events[1]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user