Skip to content

test: extract and speed up db test helpers into atelier-testing library#341

Merged
Gipphe merged 1 commit intomainfrom
refactor/database-test-setup
Mar 19, 2026
Merged

test: extract and speed up db test helpers into atelier-testing library#341
Gipphe merged 1 commit intomainfrom
refactor/database-test-setup

Conversation

@cgeorgii
Copy link
Member

Shared postgres server + template database

● Before → After: 117 tests in ~10s → 0.56s

Previously each spec group started its own TmpPostgres server and ran sqitch migrations (~750ms × 8 groups). Now a single server starts in a background thread and migrations run once into a template database. Each spec group does CREATE DATABASE ... TEMPLATE instead which is near-instant.


More info:

  • Add new atelier-testing internal library with Atelier.Testing.Database
  • Share a single postgres server and template DB across the whole test process via a global MVar; sqitch migrations run exactly once
  • Use hspec's runIO for per-group DB setup combined with around for per-test truncation — eliminates (unnamed) groups in test output
  • Drop TestConfig wrapper; specs now receive DBPools directly
  • Hoard.TestHelpers.Database becomes a thin wrapper supplying hoard-specific config (roles, schema name, sqitch runner)

@cgeorgii cgeorgii requested a review from Gipphe March 18, 2026 16:57
- Add new `atelier-testing` internal library with `Atelier.Testing.Database`
- Share a single postgres server and template DB across the whole test
  process via a global `MVar`; sqitch migrations run exactly once
- Use hspec's `runIO` for per-group DB setup combined with `around` for
  per-test truncation — eliminates `(unnamed)` groups in test output
- Drop `TestConfig` wrapper; specs now receive `DBPools` directly
- `Hoard.TestHelpers.Database` becomes a thin wrapper supplying
  hoard-specific config (roles, schema name, sqitch runner)
@cgeorgii cgeorgii force-pushed the refactor/database-test-setup branch from 03a1d99 to 0c7ab85 Compare March 19, 2026 12:44
@Gipphe Gipphe added this pull request to the merge queue Mar 19, 2026
Merged via the queue into main with commit 21710b8 Mar 19, 2026
2 checks passed
@Gipphe Gipphe deleted the refactor/database-test-setup branch March 19, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants