Fix second-pass review findings: subscription leak on rebuild, metrics accuracy, and MxAccess startup recovery

- Preserve and replay subscription ref counts across address space rebuilds to prevent MXAccess subscription leaks
- Mark read timeouts and write failures as unsuccessful in PerformanceMetrics for accurate health reporting
- Add deferred MxAccess reconnect path when initial connection fails at startup
- Update code review document with verified completions and new findings
- Add covering tests for all fixes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-03-25 09:41:12 -04:00
parent 71254e005e
commit 09ed15bdda
12 changed files with 307 additions and 51 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Shouldly;
using Xunit;
using ZB.MOM.WW.LmxOpcUa.Host;
@@ -69,5 +70,60 @@ namespace ZB.MOM.WW.LmxOpcUa.Tests.Wiring
service.Stop();
}
}
[Fact]
public async Task Start_WhenMxAccessIsInitiallyDown_MonitorReconnectsInBackground()
{
var config = new AppConfiguration
{
OpcUa = new OpcUaConfiguration
{
Port = 14841,
GalaxyName = "TestGalaxy",
EndpointPath = "/LmxOpcUa"
},
MxAccess = new MxAccessConfiguration
{
ClientName = "Test",
MonitorIntervalSeconds = 1,
AutoReconnect = true
},
GalaxyRepository = new GalaxyRepositoryConfiguration(),
Dashboard = new DashboardConfiguration { Enabled = false }
};
var proxy = new FakeMxProxy { ShouldFailRegister = true };
var repo = new FakeGalaxyRepository
{
Hierarchy = new List<GalaxyObjectInfo>
{
new GalaxyObjectInfo { GobjectId = 1, TagName = "TestObj", BrowseName = "TestObj", ParentGobjectId = 0, IsArea = false }
},
Attributes = new List<GalaxyAttributeInfo>
{
new GalaxyAttributeInfo { GobjectId = 1, TagName = "TestObj", AttributeName = "TestAttr", FullTagReference = "TestObj.TestAttr", MxDataType = 5, IsArray = false }
}
};
var service = new OpcUaService(config, proxy, repo);
service.Start();
try
{
service.ServerHost.ShouldNotBeNull();
service.MxClient.ShouldNotBeNull();
service.MxClient!.State.ShouldBe(ConnectionState.Error);
proxy.ShouldFailRegister = false;
await Task.Delay(2500);
service.MxClient.State.ShouldBe(ConnectionState.Connected);
proxy.RegisterCallCount.ShouldBeGreaterThan(1);
}
finally
{
service.Stop();
}
}
}
}