Skip to content

Run the test suite in parallel (2.24x faster) - #1412

Open
kennethrioja wants to merge 1 commit into
ElixirTeSS:masterfrom
kennethrioja:faster-tests
Open

kennethrioja wants to merge 1 commit into
ElixirTeSS:masterfrom
kennethrioja:faster-tests

Conversation

@kennethrioja

@kennethrioja kennethrioja commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary of changes

  • Run the Minitest suite in parallel: 4 workers by default ([Etc.nprocessors, 4].min). PARALLEL_WORKERS=N overrides it, and PARALLEL_WORKERS=1 runs serially. Rails only goes parallel for 50+ tests, so single files and system tests stay serial.
  • Each worker gets its own database (created by Rails), its own Redis DB (2 + worker) and TEST_ENV_NUMBER.
  • Files that tests write and read back are now per worker: test job results (HasTestJob), test sitemaps (config/sitemap.rb, sitemap_test.rb) and scraper logfiles (scraper_test.rb).
  • Warm the Sprockets theme stylesheet and JS lookup once before forking, so each worker doesn't pay ~3s (~11s under contention).
  • SimpleCov: merge worker results (SimpleCov.result only in workers) and clear stale resultsets at start, so serial and parallel runs report the same coverage.
  • The test log level defaults to warn (RAILS_LOG_LEVEL=debug restores the old behaviour).
  • GitHub ingestor TTL tests use travel_to/travel instead of sleep(1)/sleep(2). This also fixes a flaky 604799 vs 604800 assertion under load. A mutation check confirmed the tests still fail when the TTL is wrong.
  • docs/docker.md documents the new options.

No test was removed, skipped or weakened: every run has the same 1600 tests and 8730 assertions.

Motivation and context

The full suite was slow to run in Docker. With the default 4 workers (benchmark below, same machine):

  • Minitest time: 91.2s → 40.8s, 55.3% less time (2.24× faster).
  • Wall time of docker compose run test rails test: 97.4s → 50s, 48.7% less time (1.95× faster).

The tests, assertions and coverage are unchanged: 1600 tests, 8730 assertions, 0 failures, 96.7% coverage (24437/25270 LOC, identical in serial and parallel).

Screenshots

Full suite run with PARALLEL_WORKERS=1..10 (Docker on Apple Silicon, 10 CPUs, 7.65 GiB VM shared with the dev stack):

Test suite duration and peak memory for 1 to 10 parallel workers

Workers Wall (s) Minitest (s) Peak mem (GiB) Result
before (serial) 97.4 91.2 – 1600 tests, 0 failures
1 76 69.6 0.92 1600 tests, 0 failures, 0 errors
2 61 50.8 1.65 1600 tests, 0 failures, 0 errors
3 50 40.9 2.17 1600 tests, 0 failures, 0 errors
4 (default) 50 40.8 2.56 1600 tests, 0 failures, 0 errors
5 49 41.0 3.04 1600 tests, 0 failures, 0 errors
6 59 48.8 3.49 1600 tests, 0 failures, 0 errors
7 68 59.2 4.05 1600 tests, 0 failures, 0 errors
8 65 56.0 4.08 1600 tests, 0 failures, 0 errors
9 94 85.6 4.91 1600 tests, 0 failures, 0 errors
10 126 115.9 5.16 1600 tests, 0 failures, 0 errors

3–5 workers is the sweet spot. Beyond that, CPU/IO contention makes runs slower, and in earlier runs workers were OOM-killed. A killed worker makes Rails wait forever, which is why the default is capped at 4. Even serially the suite is faster (91.2s → 69.6s) thanks to the log level, asset warm-up and sleep removals.

Commands run (isolated Docker project, PREFIX=tess-faster-tests):

  • docker compose -p tess-faster-tests --profile test run --rm -e PARALLEL_WORKERS=$w test rails test for w=1..10: all passed (table above).
  • docker compose -p tess-faster-tests --profile test run --rm test rails test (default, 4 workers): 1600 tests, 0 failures, 0 errors, 10 skips, 39.4s, 96.7% coverage.

This PR was done using GitHub Copilot CLI with Claude Opus 5.5 and 879.15 AIC (KR comment: that's too much for a ~2h session... still learning here).

Checklist

  • I have read and followed the CONTRIBUTING guide.
  • I confirm that I have the authority necessary to make this contribution on behalf of its copyright owner and agree to license it to the TeSS codebase under the BSD license.

- Parallelise Minitest (4 workers by default, PARALLEL_WORKERS overrides,
  1 = serial); each worker gets its own DB, Redis DB and TEST_ENV_NUMBER.
- Make files written/read back by tests per worker (test job results,
  sitemaps, scraper logs).
- Warm the Sprockets theme/JS lookup before forking.
- Merge SimpleCov results from workers and clear stale resultsets at start.
- Default test log level to warn (RAILS_LOG_LEVEL overrides).
- Replace real sleeps in GitHub ingestor TTL tests with time travel.
- Document parallel test options in docs/docker.md.

Full suite: 91s -> ~40s (Minitest), same 1600 tests, 0 failures, 96.7% coverage.

Co-authored-by: Copilot <[email protected]>,
using Claude Opus 5.5 and 803+ AIC.
@kennethrioja

Copy link
Copy Markdown
Contributor Author

It seems like #1411 has the same Capybara issue from the systems' tests.

@kennethrioja

Copy link
Copy Markdown
Contributor Author

I can see also the improvement in the GitHub action in GitHub, when we compare Docker tests / test in #1412, I have Finished tests in 85.569463s, 18.7567 tests/s, 103.0040 assertions/s. and in the latest #1411 it is: Finished tests in 191.252504s, 8.3920 tests/s, 46.2687 assertions/s. It gives the same 2.24x speedup :)

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.

1 participant