Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<IMaintenanceStateProvider, NullMaintenanceStateProvider>();

// Add test authentication scheme that bypasses OpenIddict validation
services.AddTestAuthentication();

Expand Down Expand Up @@ -182,4 +196,14 @@ private static void TryDeleteWolverineDb()
}
#pragma warning restore CA1031
}

/// <summary>
/// Always reports the application as live. Prevents a stale <c>.maintenance</c>
/// sentinel on the developer's machine from returning 503 for every test request.
/// </summary>
private sealed class NullMaintenanceStateProvider : IMaintenanceStateProvider
{
public ValueTask<MaintenanceState?> GetAsync(CancellationToken cancellationToken = default) =>
ValueTask.FromResult<MaintenanceState?>(null);
}
}
Loading