test(worker): assert FakeRuntimeSession release wait, bound live-probe waits (mxaccessgw#223)

FakeRuntimeSession ignored the bool from releaseDispatch.Wait(safety net); it now
faults the dispatch with a TimeoutException when nothing released it. The four
skip-gated live probe files' unbounded done.Wait() calls are bounded (10 min) and
assert, with the probe thread made background so a wedged COM call cannot hang
the test host. (Worker.Tests part only; gateway part tracked separately.)

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 13:29:10 -05:00
parent 2e52f9f5e8
commit 381e772766
5 changed files with 30 additions and 11 deletions
@@ -31,6 +31,9 @@ namespace ZB.MOM.WW.MxGateway.Worker.Tests.Probes;
/// </summary>
public sealed class AlarmClientWmProbeTests : IDisposable
{
// Upper bound on a skip-gated live probe so a wedged COM call fails the test instead of blocking forever.
private static readonly TimeSpan LiveProbeTimeout = TimeSpan.FromMinutes(10);
// Probe configuration. Override in the constructor below if needed.
// Try multiple subscription expressions sequentially (each Subscribe call
// adds to the consumer's scope). The "everything" form varies by AVEVA
@@ -189,10 +192,10 @@ public sealed class AlarmClientWmProbeTests : IDisposable
pumpDone.Set();
}
});
thread.IsBackground = false;
thread.IsBackground = true; // a hung probe must not keep the test host alive past the bounded wait
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
pumpDone.Wait();
Assert.True(pumpDone.Wait(LiveProbeTimeout), "Live probe thread did not finish within " + LiveProbeTimeout + ".");
thread.Join();
// 3. Drain the log to xunit output regardless of outcome — partial
@@ -62,6 +62,9 @@ namespace ZB.MOM.WW.MxGateway.Worker.Tests.Probes;
/// </summary>
public sealed class AlarmSubtagLiveSmokeTests
{
// Upper bound on a skip-gated live probe so a wedged COM call fails the test instead of blocking forever.
private static readonly TimeSpan LiveProbeTimeout = TimeSpan.FromMinutes(10);
// -------------------------------------------------------------------------
// Subtag addresses for TestMachine_001.TestAlarm001.
//
@@ -133,10 +136,10 @@ public sealed class AlarmSubtagLiveSmokeTests
catch (Exception ex) { threadException = ex; }
finally { done.Set(); }
});
thread.IsBackground = false;
thread.IsBackground = true; // a hung probe must not keep the test host alive past the bounded wait
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
done.Wait();
Assert.True(done.Wait(LiveProbeTimeout), "Live probe thread did not finish within " + LiveProbeTimeout + ".");
thread.Join();
output.WriteLine(string.Format("Captured {0} log line(s):", log.Count));
@@ -174,10 +177,10 @@ public sealed class AlarmSubtagLiveSmokeTests
catch (Exception ex) { threadException = ex; }
finally { done.Set(); }
});
thread.IsBackground = false;
thread.IsBackground = true; // a hung probe must not keep the test host alive past the bounded wait
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
done.Wait();
Assert.True(done.Wait(LiveProbeTimeout), "Live probe thread did not finish within " + LiveProbeTimeout + ".");
thread.Join();
List<string> lines = new List<string>();
@@ -25,6 +25,9 @@ namespace ZB.MOM.WW.MxGateway.Worker.Tests.Probes;
/// </summary>
public sealed class AlarmsLiveSmokeTests
{
// Upper bound on a skip-gated live probe so a wedged COM call fails the test instead of blocking forever.
private static readonly TimeSpan LiveProbeTimeout = TimeSpan.FromMinutes(10);
private static readonly string SubscriptionExpression =
$@"\\{Environment.MachineName}\Galaxy!DEV";
private static readonly TimeSpan PumpDuration = TimeSpan.FromSeconds(45);
@@ -55,10 +58,10 @@ public sealed class AlarmsLiveSmokeTests
catch (Exception ex) { threadException = ex; }
finally { done.Set(); }
});
thread.IsBackground = false;
thread.IsBackground = true; // a hung probe must not keep the test host alive past the bounded wait
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
done.Wait();
Assert.True(done.Wait(LiveProbeTimeout), "Live probe thread did not finish within " + LiveProbeTimeout + ".");
thread.Join();
output.WriteLine($"Captured {log.Count} log line(s):");
@@ -23,6 +23,9 @@ namespace ZB.MOM.WW.MxGateway.Worker.Tests.Probes;
/// </summary>
public sealed class WnWrapConsumerProbeTests
{
// Upper bound on a skip-gated live probe so a wedged COM call fails the test instead of blocking forever.
private static readonly TimeSpan LiveProbeTimeout = TimeSpan.FromMinutes(10);
private static readonly string MachineName = Environment.MachineName;
private static readonly string SubscriptionExpression =
$@"\\{MachineName}\Galaxy!DEV";
@@ -65,10 +68,10 @@ public sealed class WnWrapConsumerProbeTests
catch (Exception ex) { threadException = ex; }
finally { done.Set(); }
});
thread.IsBackground = false;
thread.IsBackground = true; // a hung probe must not keep the test host alive past the bounded wait
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
done.Wait();
Assert.True(done.Wait(LiveProbeTimeout), "Live probe thread did not finish within " + LiveProbeTimeout + ".");
thread.Join();
output.WriteLine($"Captured {log.Count} log line(s):");
@@ -103,7 +103,14 @@ internal sealed class FakeRuntimeSession : IWorkerRuntimeSession
if (BlockDispatch)
{
releaseDispatch.Wait(BlockedDispatchSafetyNet);
// A false result means nothing released the dispatch (Dispose also does) within
// the safety net; completing normally would hand the test a reply it never
// expected, surfacing as an opaque cancellation later, so fault loudly instead.
if (!releaseDispatch.Wait(BlockedDispatchSafetyNet))
{
throw new TimeoutException(
"FakeRuntimeSession blocked dispatch was not released within " + BlockedDispatchSafetyNet + ".");
}
}
SetSnapshot(new WorkerRuntimeHeartbeatSnapshot(