From 4b15419b4dc782e2d160615ececea32228f4ce86 Mon Sep 17 00:00:00 2001 From: Christin Date: Fri, 20 Nov 2026 02:01:01 +0100 Subject: [PATCH] build(make): cap the parallel workers of test-ci test-ci ran the tests without a server with `-n auto`, one pytest-xdist worker per core. On a machine with 32 cores and 16 GB of memory this exhausted the threads (Windows, `RuntimeError: can't start new thread`) or the memory (WSL); with eight workers all parts passed (reported in the review of this pull request). The target now adds `--maxprocesses=$(TEST_CI_MAX_WORKERS)` with a default of 8, so it still starts one worker per core, but at most eight. `make test-ci TEST_CI_MAX_WORKERS=` changes the limit. CI is not affected: its jobs call pytest themselves, on runners with four cores. Additional changes Describe the limit, `--maxprocesses` and `PYTEST_XDIST_AUTO_NUM_WORKERS` in the developer documentation Refs #1553 Co-Authored-By: Claude Fable 5.2 Assisted-by: Claude Code (claude-fable-5-2) --- Makefile | 7 +++++-- docs/develop/develop.md | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index bbee92f1..32ab851d 100644 --- a/Makefile +++ b/Makefile @@ -137,15 +137,18 @@ test: $(PYTEST) -vs --cov src --cov-report term-missing # Target to run tests as done by CI on Github (.github/workflows/pytest.yml), one part after -# the other: the server tests (test-server), the other tests on all cores (test-shard, without +# the other: the server tests (test-server), the other tests in parallel (test-shard, without # splitting them into shards), the Sphinx build (docs-test) and the Docker checks (docker-test). # Every test runs once. The coverage report covers the first two parts, like the test job. # The browser tests (browser-test) have their own target test-browser. +# The parallel part starts one pytest-xdist worker per core, but at most TEST_CI_MAX_WORKERS: +# one worker per core runs out of memory or threads on machines with many cores. +TEST_CI_MAX_WORKERS ?= 8 test-ci: export COVERAGE_CORE := sysmon test-ci: @echo "Running tests as CI..." $(PYTEST) --finalize --check-config-side-effect -m "eos_server and not docs and not docker" -vs --durations=25 --cov src --cov-report= - $(PYTEST) --finalize --check-config-side-effect -m "not eos_server and not docs and not docker" -n auto -v --durations=25 --cov src --cov-append --cov-report term-missing + $(PYTEST) --finalize --check-config-side-effect -m "not eos_server and not docs and not docker" -n auto --maxprocesses=$(TEST_CI_MAX_WORKERS) -v --durations=25 --cov src --cov-append --cov-report term-missing $(PYTEST) --finalize --check-config-side-effect -m docs -vs $(PYTEST) --finalize --check-config-side-effect -m docker -vs diff --git a/docs/develop/develop.md b/docs/develop/develop.md index 0e3f9fb2..cca57b23 100644 --- a/docs/develop/develop.md +++ b/docs/develop/develop.md @@ -636,11 +636,17 @@ CI runs every test exactly once, spread over several jobs: `make test-ci` runs the tests of the jobs `test-server`, `test-shard`, `docs-test` and `docker-test` locally, with the markers and options of these jobs and one part after the other: -the server tests, the other tests with pytest-xdist on all cores (not split into shards), the -Sphinx build and the Docker checks. It prints the coverage report of the first two parts and stops -at the first part that fails. The browser tests of the `browser-test` job have their own target, +the server tests, the other tests with pytest-xdist (not split into shards), the Sphinx build and +the Docker checks. It prints the coverage report of the first two parts and stops at the first +part that fails. The browser tests of the `browser-test` job have their own target, `make test-browser`. +The parallel part of `make test-ci` starts one worker per core, but at most eight. Without the +limit a machine with many cores can run out of memory or threads: a machine with 32 cores and +16 GB of memory did, and passed with eight workers. Change the limit with +`make test-ci TEST_CI_MAX_WORKERS=`. CI is not affected: its jobs call pytest themselves, on +runners with four cores. + The coverage report of the `test` job is combined from the parts. It differs from the report of one plain run in a few lines, and not in exactly the same ones in every run: lines that are only executed when a test finds state left by an earlier test of the same process. With pytest-xdist @@ -664,6 +670,11 @@ other. They carry the `eos_server` marker, set automatically for every test that Without `--dist loadgroup` these tests collide. Give a test that binds the ports without the fixture the marker itself (`@pytest.mark.eos_server`). +`-n auto` starts one worker per core. On a machine with many cores, limit the workers with +`--maxprocesses=`, or set the environment variable `PYTEST_XDIST_AUTO_NUM_WORKERS=`, which +replaces the number of cores that `-n auto` detects. `--maxprocesses` also limits a number set by +the variable, so in `make test-ci` the variable can only lower the number of workers. + ### Follow Coding Standards Keep your code consistent with existing style and conventions.