Replace per-test database reseeding with a snapshot restore in backend tests#910
Merged
Conversation
… main with account
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary & Motivation
Backend endpoint tests recreated the schema with
EnsureCreated()and reran the fullDatabaseSeederon a fresh in-memory SQLite connection for every test, so the cost of seeding was paid again on every test and grew with every fixture added to the seeder. This change seeds the schema and fixtures once into a template database and fills each test's connection with a binary copy throughSqliteConnection.BackupDatabase. The restore cost is effectively constant in the number of fixtures, so seeding no longer scales with the size of the seed data.accountendpoint, back-office, and external-authentication base tests now restore from a shared seeded template (SeededDatabaseTemplate) instead of callingEnsureCreated()and reseeding per test. The template is seeded once through the real dependency injection graph so Entity Framework interceptors behave as in production, and a lock serializes the binary copies that feed each test.maintest infrastructure is brought to parity withaccount: a single host shared per test class (MainWebApplicationFactory, with per-test state carried through anAsyncLocalMainTestContext) plus the same snapshot seeding, replacing the per-test host rebuild. Themainsystem has no endpoint tests yet, so this establishes the shared pattern for the first one.accountfixtures the full backend suite drops from about 22.0 to about 20.9 seconds averaged over five runs. A controlled measurement that added 1,000 seed rows raised the per-test reseed approach to about 49 seconds while the snapshot held at about 20, so the gap grows from a few percent to well over half as fixtures expand.Checklist