r/PostgreSQL • u/Pale_Ferret_8241 • 21h ago
Commercial Running 19 integration & concurrency checks against a real PostgreSQL 18 DB instead of mocking SQL
Mocked queries in unit tests are fast, but they miss real lock contention, transaction ordering, and constraint behavior when multiple requests hit the database at once.
While hardening a multi-tenant backend (27 test files / 131 tests total, plus 19 integration and concurrency checks) against an isolated PostgreSQL 18 instance, testing against real Postgres caught edge cases around concurrent mutations, rate-limit counters, and webhook/state transitions that mocked unit tests never surfaced. The attached 26-second clip shows the test suite passing and moves straight into the live workspace.
For those running integration or concurrency tests against real Postgres: how do you isolate state between test runs (per-test transactions, fresh schema/DB, or reset scripts) while keeping execution times fast?