diff --git a/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmClientWmProbeTests.cs b/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmClientWmProbeTests.cs index 6e74ba81..d28e77e8 100644 --- a/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmClientWmProbeTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmClientWmProbeTests.cs @@ -31,6 +31,9 @@ namespace ZB.MOM.WW.MxGateway.Worker.Tests.Probes; /// 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 diff --git a/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmSubtagLiveSmokeTests.cs b/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmSubtagLiveSmokeTests.cs index 57ab5527..4c046716 100644 --- a/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmSubtagLiveSmokeTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmSubtagLiveSmokeTests.cs @@ -62,6 +62,9 @@ namespace ZB.MOM.WW.MxGateway.Worker.Tests.Probes; /// 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 lines = new List(); diff --git a/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmsLiveSmokeTests.cs b/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmsLiveSmokeTests.cs index d8c6a3d1..f4738110 100644 --- a/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmsLiveSmokeTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/AlarmsLiveSmokeTests.cs @@ -25,6 +25,9 @@ namespace ZB.MOM.WW.MxGateway.Worker.Tests.Probes; /// 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):"); diff --git a/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/WnWrapConsumerProbeTests.cs b/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/WnWrapConsumerProbeTests.cs index 0f3b4f0e..c0b9dc55 100644 --- a/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/WnWrapConsumerProbeTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Worker.Tests/Probes/WnWrapConsumerProbeTests.cs @@ -23,6 +23,9 @@ namespace ZB.MOM.WW.MxGateway.Worker.Tests.Probes; /// 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):"); diff --git a/src/ZB.MOM.WW.MxGateway.Worker.Tests/TestSupport/FakeRuntimeSession.cs b/src/ZB.MOM.WW.MxGateway.Worker.Tests/TestSupport/FakeRuntimeSession.cs index 39c9ed83..2d4e3bb5 100644 --- a/src/ZB.MOM.WW.MxGateway.Worker.Tests/TestSupport/FakeRuntimeSession.cs +++ b/src/ZB.MOM.WW.MxGateway.Worker.Tests/TestSupport/FakeRuntimeSession.cs @@ -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(