Merge fix/test-class-async-disposal: xUnit v2 ignores IAsyncDisposable on test classes; teardown was dead code
ci / nightly-windev (push) Has been skipped
ci / windows-x86 (push) Successful in 1m12s
ci / java (push) Successful in 1m59s
ci / portable (push) Successful in 8m18s

This commit is contained in:
Joseph Doherty
2026-08-10 16:11:54 -04:00
@@ -11,7 +11,7 @@ using ZB.MOM.WW.MxGateway.Tests.TestSupport;
namespace ZB.MOM.WW.MxGateway.Tests.Gateway.Sessions;
public sealed class SessionWorkerClientFactoryFakeWorkerTests : IAsyncDisposable
public sealed class SessionWorkerClientFactoryFakeWorkerTests : IAsyncLifetime
{
private static readonly TimeSpan TestTimeout = TimeSpan.FromSeconds(5);
@@ -24,12 +24,19 @@ public sealed class SessionWorkerClientFactoryFakeWorkerTests : IAsyncDisposable
private readonly List<IWorkerTaskLauncher> _launchers = [];
/// <inheritdoc />
public Task InitializeAsync() => Task.CompletedTask;
/// <summary>
/// Awaits every scripted worker task so an unhandled exception fails the owning test
/// instead of surfacing later as an unobserved <see cref="TaskScheduler.UnobservedTaskException"/>.
/// This must stay on <see cref="IAsyncLifetime"/>: xUnit v2 never invokes
/// <see cref="IAsyncDisposable.DisposeAsync"/> on a test class, so under the previous
/// declaration this teardown silently never ran (the NeverReady launcher's parked infinite
/// delay was still pending in a post-run process dump).
/// </summary>
/// <returns>A task that represents the asynchronous operation.</returns>
public async ValueTask DisposeAsync()
public async Task DisposeAsync()
{
foreach (IWorkerTaskLauncher launcher in _launchers)
{