diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests/Sdk2LifecycleCloseOwnershipTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests/Sdk2LifecycleCloseOwnershipTests.cs index 7a42d89fa..93be34e4d 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests/Sdk2LifecycleCloseOwnershipTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.IntegrationTests/Sdk2LifecycleCloseOwnershipTests.cs @@ -89,6 +89,7 @@ public sealed partial class Sdk2LifecycleSoakTests }; ApplicationInstance? application = new(telemetry) { ApplicationConfiguration = config }; ServerEventRig? rig = null; + Exception? originalFailure = null; try { await config.ValidateAsync(ApplicationType.Client, ct); @@ -130,11 +131,37 @@ public sealed partial class Sdk2LifecycleSoakTests WriteCloseControl("sdk2-disposal-proofs", new { managersDisposed = 2, cachedStores = 0, pkiDescriptors = 0 }); return stoppedTargets.ToArray(); } + catch (Exception error) + { + originalFailure = error; + throw; + } finally { - if (rig is not null) await rig.DisposeAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(20), ct); - if (application is not null) await application.DisposeAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(20), ct); - if (Directory.Exists(clientRoot)) Directory.Delete(clientRoot, true); + var cleanupFailures = new List(); + try + { + try { if (rig is not null) await rig.DisposeAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(20)); } + catch (Exception error) { cleanupFailures.Add(error); } + } + finally + { + try + { + try { if (application is not null) await application.DisposeAsync().AsTask().WaitAsync(TimeSpan.FromSeconds(20)); } + catch (Exception error) { cleanupFailures.Add(error); } + } + finally + { + try { if (Directory.Exists(clientRoot)) Directory.Delete(clientRoot, true); } + catch (Exception error) { cleanupFailures.Add(error); } + } + } + if (cleanupFailures.Count > 0) + { + if (originalFailure is not null) cleanupFailures.Insert(0, originalFailure); + throw new AggregateException("Close-control cleanup failed; original failure retained when present.", cleanupFailures); + } } }