Skip to content

Conversation

@thrawn01
Copy link
Contributor

Purpose

Optimize PostgreSQL test performance by starting a single container once per go test run via TestMain, rather than starting/stopping a container for each test function. This reduces test overhead from ~20-40+ seconds to ~3-7 seconds while maintaining complete test isolation via separate databases.

Implementation

  • Add sharedPostgresContainer struct with sync.Once to ensure single container startup per test run
  • Implement CreateDatabase/DropDatabase methods that create unique databases (querator_test_1, querator_test_2, etc.) within the shared container
  • Update postgresTestSetup.Setup() to create a new database instead of starting a container
  • Update postgresTestSetup.Teardown() to drop the database instead of terminating the container
  • Add goleakOptions to ignore testcontainers Reaper goroutine across all test files
  • Handle edge cases: connection termination before database drop, defensive nil checks, best-effort cleanup on teardown

- Add sharedPostgresContainer struct with sync.Once for single container startup
- Implement CreateDatabase/DropDatabase for per-test database isolation
- Update postgresTestSetup to use shared container instead of per-test containers
- Add goleakOptions to ignore testcontainers Reaper goroutine
- Update all test files to use goleakOptions
- Handle conn.Close error returns in defer statements
@thrawn01 thrawn01 merged commit 67b4614 into main Dec 12, 2025
1 check passed
@thrawn01 thrawn01 self-assigned this Dec 12, 2025
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