Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Scale the jest worker count to the machine it's running on (#83395)

Romeo Van Snick12aa79429152
diff --git a/jest.config.js b/jest.config.js
index cdba88d577b..091ad33875a 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -1,6 +1,19 @@
// @ts-check
/** eslint-disable-next-line import/no-commonjs */
+const { cpus } = require("os");
+
const baseConfig = require("./jest.base.conf.js");
+
+// Four workers left most of a developer machine idle: on fourteen cores the
+// suite takes 390s at four workers and 200s at eight, and twelve is slower
+// again. A four-core CI runner resolves to the four workers it had before.
+const WORKER_SHARE_OF_CORES = 0.6;
+const MIN_WORKERS = 4;
+const maxWorkers = Math.max(
+ MIN_WORKERS,
+ Math.round(cpus().length * WORKER_SHARE_OF_CORES),
+);
+
// Heap measurement specs. They run from jest.memory.conf.js, never from the
// default sharded run, because they need --expose-gc and a quiet heap.
const MEMORY_TEST_PATTERN = "\\.leak\\.unit\\.spec\\.";
@@ -23,6 +36,7 @@ const config = {
"jest-watch-typeahead/testname",
],
testTimeout: 30000,
+ maxWorkers,
// CI narrows a run to the plan's spec files by pointing this at a JSON list.
...(process.env.JEST_TEST_PATHS_FILE && {
filter: "<rootDir>/frontend/test/jest-test-paths-filter.ts",
diff --git a/package.json b/package.json
index 5b855d393b4..12c98d1b8df 100644
--- a/package.json
+++ b/package.json
@@ -498,8 +498,8 @@
"test-timezones": "bun install && ./frontend/test/__runner__/run_timezone_tests",
"test-memory": "node --expose-gc ./node_modules/.bin/jest --runInBand --config jest.memory.conf.js",
"test-timezones-unit": "jest --silent --maxWorkers=4 --config jest.tz.unit.conf.js",
- "test-unit": "bun run build:cljs && jest --ignoreProjects ci-scripts --maxWorkers=4",
- "test-unit-keep-cljs": "jest --ignoreProjects ci-scripts --maxWorkers=4",
+ "test-unit": "bun run build:cljs && jest --ignoreProjects ci-scripts",
+ "test-unit-keep-cljs": "jest --ignoreProjects ci-scripts",
"test-unit-watch": "bun run test-unit --watch",
"test-unit-watch:cljs": "bun run concurrently -n 'cljs,tests' 'bun run build-watch:cljs' 'bun run test-unit-keep-cljs --watch'",
"test-visual:loki": "NODE_ENV=development loki test --chromeFlags='--headless --disable-gpu' ",