Skip to content

Lower Backend and Postgres test times #9038

Open

Description

@andypalmi

The Backend tests and Postgres tests jobs take about 20 minutes each. On a recent green run on main, the unit test step took 950s on SQLite and 1124s on Postgres, and both jobs also waited about 1.5 minutes for the TypeScript drift check before starting.

Findings

  1. About 70% of the unit suite time is spent in hooks, not tests. setupApp runs 423 times, and each boot takes about 0.5s on SQLite and 0.7s on Postgres. On Postgres, each boot also drops and recreates the database.
  2. Seeding hashes passwords at bcrypt cost 10. Across the suite that is about 2500 hashes and 1000 compares, roughly 230s of CPU.
  3. Each boot recompiles every route schema with ajv and fast-json-stringify. That is about 30% of the remaining CPU time.
  4. mocha runs serially on one core, while the runner has 4 vCPUs.
  5. The test jobs wait for the drift check even though they don't use anything it produces.

Proposed changes

  1. Run the forge unit tests with mocha --parallel, with one Postgres database per worker.
  2. Use bcrypt cost 4 under test.
  3. Reuse compiled route schemas across app instances under test.
  4. Stop the test jobs waiting on the drift check. The summary job still requires it.

With these, the unit suite takes about 1 minute on SQLite and about 2 minutes on Postgres locally, down from 8 and 10 minutes.

Possible follow-ups

  1. On Postgres, migrate once per worker and reset the data between boots, instead of recreating the database on every boot.
  2. Boot once per file where a file only reads data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions