Close all four stability-review 2026-04-13 findings so a failed runtime probe subscription can no longer leave a phantom entry that Tick() flips to Stopped and fans out false BadOutOfService quality across a host's subtree, a silently-failed dashboard bind no longer lets the service advertise a successful start while an operator-visible endpoint is dead, the seven sync-over-async sites in LmxNodeManager (rebuild probe sync, Read, Write, four HistoryRead overrides) can no longer park the OPC UA stack thread indefinitely on a hung backend, and alarm auto-subscribe + transferred-subscription restore no longer race shutdown as untracked fire-and-forget tasks.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.LmxOpcUa.Host.Utilities;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Tests.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the bounded sync-over-async wrapper introduced by stability review 2026-04-13
|
||||
/// Finding 3. The wrapper is a backstop applied at every LmxNodeManager sync-over-async site
|
||||
/// (Read, Write, HistoryRead*, BuildAddressSpace probe sync).
|
||||
/// </summary>
|
||||
public class SyncOverAsyncTests
|
||||
{
|
||||
[Fact]
|
||||
public void WaitSync_CompletedTask_ReturnsResult()
|
||||
{
|
||||
var task = Task.FromResult(42);
|
||||
SyncOverAsync.WaitSync(task, TimeSpan.FromSeconds(1), "test").ShouldBe(42);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WaitSync_CompletedNonGenericTask_Returns()
|
||||
{
|
||||
var task = Task.CompletedTask;
|
||||
Should.NotThrow(() => SyncOverAsync.WaitSync(task, TimeSpan.FromSeconds(1), "test"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WaitSync_NeverCompletingTask_ThrowsTimeoutException()
|
||||
{
|
||||
var tcs = new TaskCompletionSource<int>();
|
||||
var ex = Should.Throw<TimeoutException>(() =>
|
||||
SyncOverAsync.WaitSync(tcs.Task, TimeSpan.FromMilliseconds(100), "op"));
|
||||
ex.Message.ShouldContain("op");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WaitSync_NeverCompletingNonGenericTask_ThrowsTimeoutException()
|
||||
{
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
Should.Throw<TimeoutException>(() =>
|
||||
SyncOverAsync.WaitSync((Task)tcs.Task, TimeSpan.FromMilliseconds(100), "op"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WaitSync_FaultedNonGenericTask_UnwrapsInnerException()
|
||||
{
|
||||
var task = Task.FromException(new InvalidOperationException("boom"));
|
||||
Should.Throw<InvalidOperationException>(() =>
|
||||
SyncOverAsync.WaitSync(task, TimeSpan.FromSeconds(1), "op"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WaitSync_FaultedGenericTask_UnwrapsInnerException()
|
||||
{
|
||||
var task = Task.FromException<int>(new InvalidOperationException("boom"));
|
||||
Should.Throw<InvalidOperationException>(() =>
|
||||
SyncOverAsync.WaitSync(task, TimeSpan.FromSeconds(1), "op"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WaitSync_NullTask_ThrowsArgumentNullException()
|
||||
{
|
||||
Should.Throw<ArgumentNullException>(() =>
|
||||
SyncOverAsync.WaitSync((Task)null!, TimeSpan.FromSeconds(1), "op"));
|
||||
Should.Throw<ArgumentNullException>(() =>
|
||||
SyncOverAsync.WaitSync((Task<int>)null!, TimeSpan.FromSeconds(1), "op"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user