Repository navigation
Commit e42ec28
committed
fix(tests): migrate the shared test database once per session
The four WebApplicationFactory variants are each their own ClassDataSource,
so each boots its own API host, but all of them share a single
PerTestSession Postgres container. Every host applied migrations on startup,
and EF's migrator is not safe to run concurrently: two hosts booting
together both see the same pending migrations and both apply them.
TUnit 1.70 happened to schedule those initializations so the first migrator
finished before the others started; 1.74 does not. That surfaced the latent
race as 30 failures in API.IntegrationTests - "type/relation/collation
already exists", duplicate keys on __EFMigrationsHistory, and queries
hitting a half-migrated schema.
Apply migrations in InMemoryDatabase.InitializeAsync, which runs once per
session, and set SKIPMIGRATION on the factories so no host migrates on boot.
This mirrors what Cron.IntegrationTests already does for the Cron host. It
also removes the stale Npgsql type-catalog hazard, since the schema is
complete before any host opens its first connection, and runs the migrations
once rather than up to four times.1 parent 0d3330e commit e42ec28
2 files changed
Lines changed: 28 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
2 | 5 | | |
3 | 6 | | |
4 | 7 | | |
| |||
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | | - | |
31 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
32 | 53 | | |
33 | 54 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
| |||
0 commit comments