From eaae2c77317f1d47e9f36920b01127586b1fc9fb Mon Sep 17 00:00:00 2001 From: Anto Subash Date: Sat, 23 May 2026 23:50:35 +0200 Subject: [PATCH] fix(events): neutralize MaintenanceModeMiddleware in test factory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The feat(maintenance) commit wired FileSystemMaintenanceStateProvider into the request pipeline unconditionally. WebApplicationFactory resolves its content root from the SimpleModule.Host project directory (template/SimpleModule.Host/), so a leftover .maintenance sentinel file there — created by `sm down` during development or testing — activates maintenance mode for the entire test host and makes every non-health request return 503. This caused PublishedEvent_Survives_The_Durable_Pipeline_End_To_End to fail with "Expected response.IsSuccessStatusCode to be True, but found False" because the PUT /api/settings request received a 503 instead of 204 NoContent. Fix: replace IMaintenanceStateProvider with NullMaintenanceStateProvider in SimpleModuleWebApplicationFactory.ConfigureWebHost so the maintenance middleware always passes through during tests, regardless of local filesystem state. --- .../SimpleModuleWebApplicationFactory.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/SimpleModule.Tests.Shared/Fixtures/SimpleModuleWebApplicationFactory.cs b/tests/SimpleModule.Tests.Shared/Fixtures/SimpleModuleWebApplicationFactory.cs index a4f6af3c..56fa4904 100644 --- a/tests/SimpleModule.Tests.Shared/Fixtures/SimpleModuleWebApplicationFactory.cs +++ b/tests/SimpleModule.Tests.Shared/Fixtures/SimpleModuleWebApplicationFactory.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using SimpleModule.AuditLogs; using SimpleModule.BackgroundJobs; +using SimpleModule.Core.Maintenance; using SimpleModule.Database; using SimpleModule.Email; using SimpleModule.FeatureFlags; @@ -92,6 +93,19 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) services ); + // Replace the file-based maintenance state provider with a no-op so that + // a leftover .maintenance sentinel on the developer's machine (or a CI + // agent that ran `sm down`) cannot block API requests and cause spurious + // test failures with 503 responses. + var maintenanceDescriptor = services.SingleOrDefault(d => + d.ServiceType == typeof(IMaintenanceStateProvider) + ); + if (maintenanceDescriptor is not null) + { + services.Remove(maintenanceDescriptor); + } + services.AddSingleton(); + // Add test authentication scheme that bypasses OpenIddict validation services.AddTestAuthentication(); @@ -182,4 +196,14 @@ private static void TryDeleteWolverineDb() } #pragma warning restore CA1031 } + + /// + /// Always reports the application as live. Prevents a stale .maintenance + /// sentinel on the developer's machine from returning 503 for every test request. + /// + private sealed class NullMaintenanceStateProvider : IMaintenanceStateProvider + { + public ValueTask GetAsync(CancellationToken cancellationToken = default) => + ValueTask.FromResult(null); + } }