chore: make integration tests 60x faster - #22
Conversation
There was a problem hiding this comment.
Pull request overview
This PR speeds up the integration test suite by avoiding per-test container startup: it reuses a single Postgres container across all integration tests in the file (resetting state between tests) and replaces LocalStack Secrets Manager with a lightweight in-process HTTP stub. It also updates the pnpm test script to build once and run all Vitest projects in a single invocation.
Changes:
- Rework
lambda.integration.test.tsto usebeforeAll/afterAllshared fixtures and reset the DB between tests. - Add reusable test fixtures:
startPostgresCluster()(testcontainers + fast PG config) andstartFakeSecretsManager()(minimal Secrets Manager stub). - Update
package.jsontestscript tobuildonce +vitest --run.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cdk-postgresql/test/lambda.integration.test.ts | Switch to shared Postgres + in-process Secrets Manager stub to reduce per-test startup cost |
| cdk-postgresql/test/fixtures/postgres-cluster.ts | New Postgres fixture that starts once and provides a reset() routine between tests |
| cdk-postgresql/test/fixtures/fake-secrets-manager.ts | New lightweight HTTP server implementing only the Secrets Manager operations used by tests |
| cdk-postgresql/package.json | Run a single build + single Vitest run for all projects |
Suppressed comments (1)
cdk-postgresql/test/lambda.integration.test.ts:68
cluster.reset()returns a Promise, but thisbeforeEachhook isn't async/awaiting it. That means the next test can start running while the database is still being wiped, causing cross-test contamination and flakiness (especially with replication slots / DB drops).
// The database container is shared by every test in this file, so each test
// starts from a blank cluster:
beforeEach(() => cluster.reset());
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Greptile SummaryThe PR speeds up integration tests by sharing one PostgreSQL container and replacing LocalStack with an in-process Secrets Manager stand-in.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| cdk-postgresql/package.json | Consolidates the package test command into one build followed by a complete Vitest run. |
| cdk-postgresql/test/fixtures/fake-secrets-manager.ts | Adds an in-process HTTP stand-in for the two Secrets Manager operations used by the handlers. |
| cdk-postgresql/test/fixtures/postgres-cluster.ts | Adds a reusable PostgreSQL test container with explicit per-test state cleanup and suite-level shutdown. |
| cdk-postgresql/test/lambda.integration.test.ts | Reuses shared PostgreSQL and Secrets Manager fixtures while resetting database state before each integration test. |
Sequence Diagram
sequenceDiagram
participant Suite as Integration suite
participant Secrets as Fake Secrets Manager
participant PG as Shared PostgreSQL
participant Test as Each test
Suite->>Secrets: Start once
Suite->>PG: Start once
Test->>PG: Reset cluster
Test->>Secrets: Store/read test secrets
Test->>PG: Exercise handlers and verify state
Suite->>Secrets: Stop after suite
Suite->>PG: Stop after suite
Reviews (3): Last reviewed commit: "fix: reject fake secrets manager startup..." | Re-trigger Greptile
Co-authored-by: pascal-botpress <179493770+pascal-botpress@users.noreply.github.com>
Co-authored-by: pascal-botpress <179493770+pascal-botpress@users.noreply.github.com>
5e6d212 to
c340c56
Compare
I'm tired of waiting