ci: make the windev CI lock exclusive, stop the scheduled double run, isolate test secrets stores (mxaccessgw#150)
Diagnosis of the retained Windows-nightly failures (119 scheduled nightlies, 28 red; job logs from the Gitea API, C:\build\mxaccessgw-ci\ci.log and the windev System log, read-only): - Checkout (#148, run 827, 2026-09-22): the windev "atomic mkdir" lock was not exclusive. New-Item -ItemType Directory checks for the directory and then calls CreateDirectory, which succeeds on an existing directory; a pwsh race harness had both contenders take it in 1900 of 2000 simultaneous rounds. A scheduled run starts windows-x86 and nightly-windev in the same second, both bootstraps got in, and the nightly's checkout died on .git/index.lock. Fix: the bootstrap (and a standalone windev-worker-ci.ps1) holds an exclusive FileShare.None handle on C:\build\mxaccessgw-ci.ci-lock instead (0 of 1000 double acquisitions in the same harness). The OS drops it if the holder dies, so a killed run leaves no stale lock, and a holder removes a leftover .git\index.lock, which can only be debris from a killed git. - windows-x86 no longer runs on the schedule: nightly-windev's live mode already runs the same Worker build + tests first, so the scheduled copy only doubled the load and created the race. - Host resources (#128/#129/#131-#135/#138, 2026-07-24..08-03): windev's System log has Resource-Exhaustion-Detector event 2004 (low virtual memory) every few minutes from 2026-07-23 until an unexpected shutdown/hard reset on 2026-08-03; OOM in MSBuild/csc/protoc, csc 0xC0000142, PowerShell dying before its first log line and SSH kex resets all fall in that window and stop after the reset. Host-side; windev-worker-ci.ps1 now logs free commit, physical memory, disk and testhost count at start and on failure so the next one is correlatable. - SSH "No route to host" (#144, 2026-09-16): windev was down (unexpected shutdown 00:58, back 05:50). - Dashboard host build (#143, run 817): two host-building test classes failed at the same instant in SqliteSecretsStoreMigrator with "cannot start a transaction within a transaction" -- parallel classes migrating the one per-process secrets store. Tests now build the gateway through TestSupport/TestGatewayHost, which gives each host its own store; TestGatewayHostTests guards it. - Gateway E2E "Worker pipe disconnected" (#142/#145/#146/#147) and handshaking-to-ready (#141) were the fake-worker partial-frame cancellation and readiness-race defects fixed in #153 (d779daf6): 7 gateway-suite failures in 51 windev runs before it, 0 in 28 since. The Worker watchdog and burst-coalescing failures (#126/#127/#139) last failed before50322bac/7da52b65(Aug 2026). - 2026-10-15..20 was the NU1903 package-audit restore failure, fixed infb20997. Docs: GatewayTesting.md (lock, host-resource triage) and scripts/ci/README.md. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+2
-1
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Options;
|
||||
using ZB.MOM.WW.GalaxyRepository;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Configuration;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Configuration;
|
||||
|
||||
@@ -114,7 +115,7 @@ public sealed class GalaxyRepositoryOptionsValidatorTests
|
||||
[Fact]
|
||||
public void Build_DefaultsBlankSnapshotCachePathToRootedDefault()
|
||||
{
|
||||
using WebApplication app = GatewayApplication.Build([]);
|
||||
using WebApplication app = TestGatewayHost.Build([]);
|
||||
|
||||
GalaxyRepositoryOptions options =
|
||||
app.Services.GetRequiredService<IOptions<GalaxyRepositoryOptions>>().Value;
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using ZB.MOM.WW.Auth.AspNetCore;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
using ZB.MOM.WW.Secrets.Ui;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Dashboard;
|
||||
@@ -35,7 +36,7 @@ public sealed class SecretsNavGateTests
|
||||
[Fact]
|
||||
public async Task ManagePolicy_AdmitsAdministrator()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IAuthorizationService authorization = app.Services.GetRequiredService<IAuthorizationService>();
|
||||
|
||||
AuthorizationResult result = await authorization.AuthorizeAsync(
|
||||
@@ -56,7 +57,7 @@ public sealed class SecretsNavGateTests
|
||||
[Fact]
|
||||
public async Task ManagePolicy_RefusesViewer()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IAuthorizationService authorization = app.Services.GetRequiredService<IAuthorizationService>();
|
||||
|
||||
AuthorizationResult result = await authorization.AuthorizeAsync(
|
||||
@@ -75,7 +76,7 @@ public sealed class SecretsNavGateTests
|
||||
[Fact]
|
||||
public async Task ManagePolicy_RefusesUnauthenticated()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IAuthorizationService authorization = app.Services.GetRequiredService<IAuthorizationService>();
|
||||
|
||||
AuthorizationResult result = await authorization.AuthorizeAsync(
|
||||
|
||||
@@ -11,6 +11,7 @@ using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Configuration;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard.Hubs;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
using AuthenticationOptions = ZB.MOM.WW.MxGateway.Server.Configuration.AuthenticationOptions;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Gateway.Dashboard;
|
||||
@@ -115,7 +116,7 @@ public sealed class AlarmFeedAuthorizationTests
|
||||
[Fact]
|
||||
public async Task AlarmsPolicy_IsRegisteredWithNonBypassableRequirement()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IAuthorizationPolicyProvider provider = app.Services
|
||||
.GetRequiredService<IAuthorizationPolicyProvider>();
|
||||
|
||||
@@ -147,7 +148,7 @@ public sealed class AlarmFeedAuthorizationTests
|
||||
|
||||
Assert.Equal(DashboardAuthenticationDefaults.AlarmsPolicy, hubAttribute?.Policy);
|
||||
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
RouteEndpoint alarmsPage = ((IEndpointRouteBuilder)app).DataSources
|
||||
.SelectMany(source => source.Endpoints)
|
||||
.OfType<RouteEndpoint>()
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Gateway.Dashboard;
|
||||
|
||||
@@ -20,7 +21,7 @@ public sealed class DashboardCookieOptionsTests
|
||||
[Fact]
|
||||
public async Task Build_ConfiguresSecureDashboardCookie()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IOptionsMonitor<CookieAuthenticationOptions> optionsMonitor = app.Services
|
||||
.GetRequiredService<IOptionsMonitor<CookieAuthenticationOptions>>();
|
||||
|
||||
@@ -49,7 +50,7 @@ public sealed class DashboardCookieOptionsTests
|
||||
[Fact]
|
||||
public async Task Build_WithRequireHttpsCookieFalse_UsesSameAsRequestAndPlainName()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build(
|
||||
await using WebApplication app = TestGatewayHost.Build(
|
||||
["--MxGateway:Dashboard:RequireHttpsCookie=false"]);
|
||||
IOptionsMonitor<CookieAuthenticationOptions> optionsMonitor = app.Services
|
||||
.GetRequiredService<IOptionsMonitor<CookieAuthenticationOptions>>();
|
||||
@@ -71,7 +72,7 @@ public sealed class DashboardCookieOptionsTests
|
||||
[Fact]
|
||||
public async Task Build_WithCookieNameOverride_UsesConfiguredName()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build(
|
||||
await using WebApplication app = TestGatewayHost.Build(
|
||||
["--MxGateway:Dashboard:CookieName=MxGatewayDashboard.env2"]);
|
||||
IOptionsMonitor<CookieAuthenticationOptions> optionsMonitor = app.Services
|
||||
.GetRequiredService<IOptionsMonitor<CookieAuthenticationOptions>>();
|
||||
|
||||
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Gateway.Dashboard;
|
||||
|
||||
@@ -16,7 +17,7 @@ public sealed class DashboardDisableLoginTests
|
||||
[Fact]
|
||||
public async Task DisableLoginOff_CookieSchemeUsesCookieHandler()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IAuthenticationSchemeProvider provider =
|
||||
app.Services.GetRequiredService<IAuthenticationSchemeProvider>();
|
||||
|
||||
@@ -32,7 +33,7 @@ public sealed class DashboardDisableLoginTests
|
||||
[Fact]
|
||||
public async Task DisableLoginOn_CookieSchemeUsesAutoLoginHandler()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build(
|
||||
await using WebApplication app = TestGatewayHost.Build(
|
||||
["--MxGateway:Dashboard:DisableLogin=true"]);
|
||||
IAuthenticationSchemeProvider provider =
|
||||
app.Services.GetRequiredService<IAuthenticationSchemeProvider>();
|
||||
@@ -49,7 +50,7 @@ public sealed class DashboardDisableLoginTests
|
||||
[Fact]
|
||||
public async Task DisableLoginOn_AutoLoginPrincipalSatisfiesAdminAndViewerPolicies()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build(
|
||||
await using WebApplication app = TestGatewayHost.Build(
|
||||
["--MxGateway:Dashboard:DisableLogin=true"]);
|
||||
IAuthorizationService authorization =
|
||||
app.Services.GetRequiredService<IAuthorizationService>();
|
||||
|
||||
@@ -7,6 +7,7 @@ using Microsoft.Extensions.Options;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard.Hubs;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Gateway.Dashboard;
|
||||
|
||||
@@ -17,7 +18,7 @@ public sealed class DashboardHubsRegistrationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardEnabled_MapsAllThreeHubsAndTokenEndpoint()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IReadOnlyList<RouteEndpoint> endpoints = ((IEndpointRouteBuilder)app).DataSources
|
||||
.SelectMany(source => source.Endpoints)
|
||||
.OfType<RouteEndpoint>()
|
||||
@@ -40,7 +41,7 @@ public sealed class DashboardHubsRegistrationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardEnabled_RegistersHubTokenService()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
|
||||
HubTokenService tokens = app.Services.GetRequiredService<HubTokenService>();
|
||||
Assert.NotNull(tokens);
|
||||
@@ -55,7 +56,7 @@ public sealed class DashboardHubsRegistrationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardEnabled_ResolvesBothEventMirrorInterfacesToOneInstance()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
|
||||
IDashboardEventBroadcaster broadcaster = app.Services.GetRequiredService<IDashboardEventBroadcaster>();
|
||||
IDashboardSessionEventSubscriber subscriber = app.Services
|
||||
@@ -74,7 +75,7 @@ public sealed class DashboardHubsRegistrationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardEnabled_ShortensCircuitRetentionAndTracksConnection()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
|
||||
CircuitOptions circuitOptions = app.Services.GetRequiredService<IOptions<CircuitOptions>>().Value;
|
||||
Assert.Equal(TimeSpan.FromSeconds(30), circuitOptions.DisconnectedCircuitRetentionPeriod);
|
||||
@@ -96,7 +97,7 @@ public sealed class DashboardHubsRegistrationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardEnabled_SharesOneBrowseSearchIndex()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
|
||||
Assert.Same(
|
||||
app.Services.GetRequiredService<DashboardBrowseSearchIndex>(),
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Gateway;
|
||||
|
||||
@@ -29,7 +30,7 @@ public sealed class DashboardSecretsMountTests
|
||||
[Fact]
|
||||
public async Task Build_RegistersSecretsAuthorizationPolicies()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
|
||||
IAuthorizationPolicyProvider policyProvider =
|
||||
app.Services.GetRequiredService<IAuthorizationPolicyProvider>();
|
||||
@@ -53,7 +54,7 @@ public sealed class DashboardSecretsMountTests
|
||||
[Fact]
|
||||
public async Task AdministratorPrincipal_SatisfiesSecretsPolicies()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IAuthorizationService authorization =
|
||||
app.Services.GetRequiredService<IAuthorizationService>();
|
||||
ClaimsPrincipal administrator = DashboardAutoLoginAuthenticationHandler.CreatePrincipal("multi-role");
|
||||
@@ -73,7 +74,7 @@ public sealed class DashboardSecretsMountTests
|
||||
[Fact]
|
||||
public async Task AnonymousPrincipal_IsDeniedSecretsPolicies()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IAuthorizationService authorization =
|
||||
app.Services.GetRequiredService<IAuthorizationService>();
|
||||
ClaimsPrincipal anonymous = new(new ClaimsIdentity());
|
||||
|
||||
@@ -9,6 +9,7 @@ using Microsoft.Extensions.Options;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Server.Metrics;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Gateway;
|
||||
|
||||
@@ -19,7 +20,7 @@ public sealed class GatewayApplicationTests
|
||||
[Fact]
|
||||
public async Task Build_MapsCanonicalHealthEndpoints()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
|
||||
var paths = ((IEndpointRouteBuilder)app).DataSources
|
||||
.SelectMany(dataSource => dataSource.Endpoints)
|
||||
@@ -37,7 +38,7 @@ public sealed class GatewayApplicationTests
|
||||
[Fact]
|
||||
public void Build_UsesSerilogLoggerProvider()
|
||||
{
|
||||
using var app = GatewayApplication.Build([]);
|
||||
using var app = TestGatewayHost.Build([]);
|
||||
var factory = app.Services.GetRequiredService<ILoggerFactory>();
|
||||
Assert.Equal("SerilogLoggerFactory", factory.GetType().Name);
|
||||
}
|
||||
@@ -54,7 +55,7 @@ public sealed class GatewayApplicationTests
|
||||
[Fact]
|
||||
public async Task Build_RegistersGatewayBrowseScopeProviderOverLibraryDefault()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
|
||||
ZB.MOM.WW.GalaxyRepository.Grpc.IGalaxyBrowseScopeProvider scopeProvider =
|
||||
app.Services.GetRequiredService<ZB.MOM.WW.GalaxyRepository.Grpc.IGalaxyBrowseScopeProvider>();
|
||||
@@ -67,7 +68,7 @@ public sealed class GatewayApplicationTests
|
||||
[Fact]
|
||||
public async Task Build_RegistersGatewayMetrics()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
|
||||
GatewayMetrics metrics = app.Services.GetRequiredService<GatewayMetrics>();
|
||||
|
||||
@@ -82,7 +83,7 @@ public sealed class GatewayApplicationTests
|
||||
// Bind an ephemeral port (:0) — xUnit runs test collections in parallel, so any
|
||||
// started-host test must avoid a fixed port to prevent a bind collision. The auth SQLite
|
||||
// store path is isolated to a per-process temp file by TestHostEnvironmentInitializer.
|
||||
await using WebApplication app = GatewayApplication.Build(["--urls=http://127.0.0.1:0"]);
|
||||
await using WebApplication app = TestGatewayHost.Build(["--urls=http://127.0.0.1:0"]);
|
||||
await app.StartAsync();
|
||||
try
|
||||
{
|
||||
@@ -103,7 +104,7 @@ public sealed class GatewayApplicationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardEnabled_MapsBlazorDashboardAndAuthEndpoints()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IReadOnlyList<RouteEndpoint> endpoints = GetRouteEndpoints(app);
|
||||
|
||||
Assert.Contains(endpoints, endpoint => endpoint.RoutePattern.RawText == "/");
|
||||
@@ -133,7 +134,7 @@ public sealed class GatewayApplicationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardEnabled_AuthEndpointsAllowAnonymousAccess()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IReadOnlyList<RouteEndpoint> endpoints = GetRouteEndpoints(app);
|
||||
|
||||
string[] anonymousEndpointNames =
|
||||
@@ -163,7 +164,7 @@ public sealed class GatewayApplicationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardEnabled_ComponentRoutesRequireAuthorization()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IReadOnlyList<RouteEndpoint> endpoints = GetRouteEndpoints(app);
|
||||
|
||||
// Razor-component endpoints are distinguished from minimal-API
|
||||
@@ -192,7 +193,7 @@ public sealed class GatewayApplicationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardEnabled_RegistersDashboardRoutesAtRoot()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build([]);
|
||||
await using WebApplication app = TestGatewayHost.Build([]);
|
||||
IReadOnlyList<RouteEndpoint> endpoints = GetRouteEndpoints(app);
|
||||
|
||||
string[] canonicalRoutes =
|
||||
@@ -224,7 +225,7 @@ public sealed class GatewayApplicationTests
|
||||
[Fact]
|
||||
public async Task Build_WhenDashboardDisabled_DoesNotMapDashboardRoutes()
|
||||
{
|
||||
await using WebApplication app = GatewayApplication.Build(["--MxGateway:Dashboard:Enabled=false"]);
|
||||
await using WebApplication app = TestGatewayHost.Build(["--MxGateway:Dashboard:Enabled=false"]);
|
||||
IReadOnlyList<RouteEndpoint> endpoints = GetRouteEndpoints(app);
|
||||
|
||||
Assert.DoesNotContain(endpoints, endpoint =>
|
||||
@@ -268,7 +269,7 @@ public sealed class GatewayApplicationTests
|
||||
// WebApplication-building test must avoid a fixed port to prevent a bind collision. The auth
|
||||
// store path is isolated by TestHostEnvironmentInitializer, so startup opens a
|
||||
// writable store and the injected misconfiguration is what fails validation.
|
||||
await using WebApplication app = GatewayApplication.Build(
|
||||
await using WebApplication app = TestGatewayHost.Build(
|
||||
[$"--{key}={value}", "--urls=http://127.0.0.1:0"]);
|
||||
|
||||
OptionsValidationException exception = await Assert.ThrowsAsync<OptionsValidationException>(
|
||||
|
||||
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Gateway;
|
||||
|
||||
@@ -36,7 +37,7 @@ public sealed class GatewayTlsBootstrapTests
|
||||
Environment.SetEnvironmentVariable(
|
||||
"MxGateway__Tls__SelfSignedCertPath", Path.Combine(certDir, "gw.pfx"));
|
||||
|
||||
WebApplication app = GatewayApplication.Build([]);
|
||||
WebApplication app = TestGatewayHost.Build([]);
|
||||
await app.StartAsync();
|
||||
try
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ using ZB.MOM.WW.Auth.ApiKeys.Admin;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Dashboard;
|
||||
using ZB.MOM.WW.MxGateway.Server.Security.Authorization;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Gateway;
|
||||
|
||||
@@ -121,7 +122,7 @@ public sealed class MetricsEndpointAuthenticationTests
|
||||
private static async Task<WebApplication> StartAsync(params string[] extraArgs)
|
||||
{
|
||||
// Ephemeral port (:0): xUnit runs collections in parallel, so a fixed port would collide.
|
||||
WebApplication app = GatewayApplication.Build(
|
||||
WebApplication app = TestGatewayHost.Build(
|
||||
[
|
||||
"--urls=http://127.0.0.1:0",
|
||||
"--MxGateway:Metrics:RequireAuthentication=true",
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Gateway;
|
||||
|
||||
/// <summary>
|
||||
/// Guards the isolation <see cref="TestGatewayHost"/> exists for: host-building test classes run in
|
||||
/// parallel, and when they shared one secrets store their concurrent pre-host migrations failed with
|
||||
/// <c>cannot start a transaction within a transaction</c> on the Windows nightly (mxaccessgw#150).
|
||||
/// </summary>
|
||||
public sealed class TestGatewayHostTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Two builds get two different secrets stores, and each build's pre-host migration created its
|
||||
/// own store — so no two hosts in the suite can migrate the same SQLite file.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task Build_GivesEachHostItsOwnMigratedSecretsStore()
|
||||
{
|
||||
await using WebApplication first = TestGatewayHost.Build();
|
||||
await using WebApplication second = TestGatewayHost.Build();
|
||||
|
||||
string? firstPath = first.Configuration["Secrets:SqlitePath"];
|
||||
string? secondPath = second.Configuration["Secrets:SqlitePath"];
|
||||
|
||||
Assert.NotNull(firstPath);
|
||||
Assert.NotNull(secondPath);
|
||||
Assert.NotEqual(firstPath, secondPath);
|
||||
Assert.NotEqual(Environment.GetEnvironmentVariable("Secrets__SqlitePath"), firstPath);
|
||||
Assert.True(File.Exists(firstPath), $"the pre-host migration did not create {firstPath}");
|
||||
Assert.True(File.Exists(secondPath), $"the pre-host migration did not create {secondPath}");
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ using ZB.MOM.WW.Auth.ApiKeys.Sqlite;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
using ZB.MOM.WW.MxGateway.Server.Configuration;
|
||||
using ZB.MOM.WW.MxGateway.Server.Security.Authentication;
|
||||
using ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.Security.Authentication;
|
||||
|
||||
@@ -70,7 +71,7 @@ public sealed class SqliteAuthStoreTests : IDisposable
|
||||
string databasePath = CreateTempDatabasePath();
|
||||
await CreateSchemaVersionDatabaseAsync(databasePath, SqliteAuthSchema.CurrentVersion + 1);
|
||||
|
||||
await using WebApplication app = GatewayApplication.Build(
|
||||
await using WebApplication app = TestGatewayHost.Build(
|
||||
[
|
||||
$"--MxGateway:Authentication:SqlitePath={databasePath}",
|
||||
"--urls=http://127.0.0.1:0"
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using ZB.MOM.WW.MxGateway.Server;
|
||||
|
||||
namespace ZB.MOM.WW.MxGateway.Tests.TestSupport;
|
||||
|
||||
/// <summary>
|
||||
/// Builds the full gateway host for a test with a secrets store of its own.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <see cref="GatewayApplication.Build"/> runs the secrets-store migrator before the host exists
|
||||
/// (and the runtime registration migrates it again on start). <see cref="TestHostEnvironmentInitializer"/>
|
||||
/// points every host in the test process at one per-process store, so host-building test classes
|
||||
/// running in parallel migrated that one SQLite file concurrently. On the Windows nightly that
|
||||
/// surfaced as <c>SqliteException: cannot start a transaction within a transaction</c> from
|
||||
/// <c>SqliteSecretsStoreMigrator.MigrateAsync</c> in two classes at once (run 817, 2026-09-15,
|
||||
/// mxaccessgw#143/#150). No host-building test shares or seeds secrets across hosts, so each
|
||||
/// build gets a fresh store and the concurrent-migration window no longer exists.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The path is passed as a command-line argument, which outranks the process-wide
|
||||
/// <c>Secrets__SqlitePath</c> default. Tests that deliberately set that variable to exercise the
|
||||
/// store-path guard call <see cref="GatewayApplication.CreateBuilder"/> directly and are unaffected.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
internal static class TestGatewayHost
|
||||
{
|
||||
/// <summary>Builds the gateway with <paramref name="args"/> and an isolated secrets store.</summary>
|
||||
/// <param name="args">Command-line arguments, as for <see cref="GatewayApplication.Build"/>.</param>
|
||||
/// <returns>The built (not started) gateway application.</returns>
|
||||
public static WebApplication Build(params string[] args)
|
||||
{
|
||||
string secretsPath = Path.Combine(
|
||||
Path.GetTempPath(),
|
||||
$"mxgw-tests-{Environment.ProcessId}",
|
||||
$"secrets-{Guid.NewGuid():N}.db");
|
||||
return GatewayApplication.Build([.. args, $"--Secrets:SqlitePath={secretsPath}"]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user