fix(driver-galaxy): resolve High code-review findings (Driver.Galaxy-002, Driver.Galaxy-008)

Driver.Galaxy-002 — DataTypeMap.Map had no Int64 arm though MxValueDecoder/
MxValueEncoder both fully support Int64. Galaxy attributes with the Int64
mx_data_type code fell through to the String default, creating a String
address-space node while runtime reads decoded a boxed long. Added
`6 => DriverDataType.Int64`, extending the contiguous 0..5 scheme so the type
map agrees with the decoder/encoder on all seven Galaxy data types.

Driver.Galaxy-008 — after a stream fault the EventPump's StreamEvents consumer
loop exited and its channel completed; EventPump.Start() is a no-op on a
completed-but-non-null loop, so a replayed subscription had no consumer and
ReplayAsync never re-registered the post-reconnect item handles. ReplayAsync
now recreates the EventPump (RestartEventPumpForReplay) and rebinds the
SubscriptionRegistry per subscription with the fresh item handles returned by
the post-reconnect SubscribeBulkAsync, via new SubscriptionRegistry.SnapshotEntries
and Rebind APIs.

Regression tests: DataTypeMapTests (every code incl. Int64), SubscriptionRegistry
Tests (Rebind/SnapshotEntries), EventPumpStreamFaultTests (faulted pump dead,
fresh pump resumes dispatch).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-22 06:59:09 -04:00
parent c9e446387a
commit 7f2e144f8d
7 changed files with 345 additions and 15 deletions

View File

@@ -0,0 +1,48 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Browse;
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Tests.Browse;
/// <summary>
/// Regression coverage for Driver.Galaxy-002 (High): every Galaxy <c>mx_data_type</c>
/// code in the contiguous 0..6 scheme must map to the matching <see cref="DriverDataType"/>.
/// The Int64 arm (code 6) was missing, so an Int64 attribute fell through to the
/// <see cref="DriverDataType.String"/> default — a String address-space node while
/// runtime reads decoded a boxed <c>long</c>. <see cref="DataTypeMap"/> must now agree
/// with <c>MxValueDecoder</c> / <c>MxValueEncoder</c>, which both fully support Int64.
/// </summary>
public sealed class DataTypeMapTests
{
[Theory]
[InlineData(0, DriverDataType.Boolean)]
[InlineData(1, DriverDataType.Int32)]
[InlineData(2, DriverDataType.Float32)]
[InlineData(3, DriverDataType.Float64)]
[InlineData(4, DriverDataType.String)]
[InlineData(5, DriverDataType.DateTime)]
[InlineData(6, DriverDataType.Int64)]
public void Map_KnownCode_MapsToExpectedDriverDataType(int mxDataType, DriverDataType expected)
{
DataTypeMap.Map(mxDataType).ShouldBe(expected);
}
[Fact]
public void Map_Int64Code_DoesNotFallThroughToStringDefault()
{
// The bug: Int64 (code 6) used to hit the `_ => String` default.
DataTypeMap.Map(6).ShouldBe(DriverDataType.Int64);
DataTypeMap.Map(6).ShouldNotBe(DriverDataType.String);
}
[Theory]
[InlineData(7)]
[InlineData(99)]
[InlineData(-1)]
public void Map_UnknownCode_FallsBackToString(int mxDataType)
{
// Forward-compatibility fallback for codes the driver doesn't recognise.
DataTypeMap.Map(mxDataType).ShouldBe(DriverDataType.String);
}
}