The backend half of the sweep RD-18 did for the front end. git blame holds the provenance and stays correct when the code moves; the comment names a closed ticket and tells the reader nothing the sentence around it does not. public/letter.css and LetterHtml.golden.html change together, because the renderer inlines the CSS and the golden file snapshots the result. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
45 lines
2.4 KiB
C#
45 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
|
|
// These stores read a single static Db.ConnectionString (there's no DI, matching
|
|
// their earlier static-Dictionary shape — see Data/Db.cs). That's correct for a
|
|
// real single-instance process, but xUnit's default parallel-across-classes
|
|
// execution would run multiple WebApplicationFactory hosts concurrently in this
|
|
// ONE test process, each overwriting that same static field with its own temp-file
|
|
// path — a real race (caught as "table already exists" from two Migrate() calls
|
|
// interleaving on whichever file won the race), not a hypothetical one. Serializing
|
|
// test classes is the fix, not a redesign of the stores for a test-only concern.
|
|
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
|
|
|
namespace BigRegister.Tests;
|
|
|
|
/// <summary>
|
|
/// A migration moved Applications/Documents/Briefs off in-memory dictionaries onto a real
|
|
/// SQLite file (see Data/Db.cs). Unlike static dictionaries, a shared file path
|
|
/// would let concurrent test classes' WebApplicationFactory instances hit the same
|
|
/// file at once — xUnit runs different test classes in parallel by default, and
|
|
/// SQLite tolerates only one writer at a time, so that's a real "database is
|
|
/// locked" flake risk, not a hypothetical one. Every test class below points at its
|
|
/// own throwaway file instead, deleted when the factory (and its class's tests) are
|
|
/// done — the same one-store-per-class isolation the old dictionaries gave for free.
|
|
/// </summary>
|
|
public sealed class TestWebApplicationFactory : WebApplicationFactory<Program>
|
|
{
|
|
private readonly string _dbPath = Path.Combine(Path.GetTempPath(), $"bigregister-test-{Guid.NewGuid():N}.db");
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder) => builder
|
|
.UseSetting("ConnectionStrings:AppDb", $"Data Source={_dbPath}")
|
|
// A fixed shared secret so NotificatieTests can exercise the accept path —
|
|
// the appsettings.json default is "" (reject everything), which no test should rely on.
|
|
.UseSetting("Zgw:NotificatieAuthorization", "test-nrc-secret");
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
base.Dispose(disposing);
|
|
if (!disposing) return;
|
|
File.Delete(_dbPath);
|
|
File.Delete(_dbPath + "-shm"); // ponytail: best-effort — WAL sidecar files if SQLite created any.
|
|
File.Delete(_dbPath + "-wal");
|
|
}
|
|
}
|