From 960c5e93bc78381a21af2d02c08380fb25ea985d Mon Sep 17 00:00:00 2001 From: Paul DeVito Date: Sun, 25 Oct 2026 12:19:22 +0200 Subject: [PATCH] fix(tests): create the functional test clients under a lock WebApplicationFactory adds each client to a List with no lock. The FunctionalTests create one client in each TestBase constructor, and TUnit runs those constructors in parallel. Two adds at the same time can lose a client or leave a null slot, and DisposeAsync then throws in the AfterAssembly hook. TestingWebApplicationFactory.CreateClient now takes a lock around the base call, the same pattern as BffApp in the Bff tests. Closes #107 --- .../TestingWebApplicationFactory.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/FullstackTemplate.FunctionalTests/TestingWebApplicationFactory.cs b/tests/FullstackTemplate.FunctionalTests/TestingWebApplicationFactory.cs index 4331a20..91c3def 100644 --- a/tests/FullstackTemplate.FunctionalTests/TestingWebApplicationFactory.cs +++ b/tests/FullstackTemplate.FunctionalTests/TestingWebApplicationFactory.cs @@ -25,6 +25,10 @@ public sealed class TestingWebApplicationFactory : WebApplicationFactory /// The machine client that the test server lets manage all tenants. It also reads the rows of all tenants. /// @@ -125,6 +129,12 @@ public async Task InitializeAsync() Instance = this; } + public new HttpClient CreateClient() + { + lock (_clientLock) + return base.CreateClient(); + } + public override async ValueTask DisposeAsync() { await base.DisposeAsync();