test: guarantee driver fixture cleanup without masking failures

This commit is contained in:
Joseph Doherty
2026-10-13 16:36:38 -04:00
parent 5310a7e07a
commit eed7cc7d75
14 changed files with 602 additions and 89 deletions
+32
View File
@@ -0,0 +1,32 @@
namespace ZB.MOM.WW.OtOpcUa.Tests;
internal static class FixtureCleanup
{
internal const string SecondaryExceptionKey = "FixtureCleanup.SecondaryException";
internal static async Task RunAsync(Func<Task> body, Func<Task> cleanup, Action<Exception> report)
{
Exception? primary = null;
try
{
await body();
}
catch (Exception failure)
{
primary = failure;
throw;
}
finally
{
try
{
await cleanup();
}
catch (Exception secondary) when (primary is not null)
{
try { primary.Data[SecondaryExceptionKey] = secondary; } catch { }
try { report(secondary); } catch { }
}
}
}
}