Repository navigation
Faster backend unit tests: cut repeated work and real waits, run in parallel - #136
Merged
Merged
Conversation
…rallel The backend unit job ran 20-28 min in CI. Most of the time went to work repeated in thousands of tests and to a serial run, not to slow individual tests. - Parse the merged ontology, plan rules, gap rules and the shop fixture once per process in the test support modules (Ontology, PlanRules, GapRules and the shop models are frozen). Base the ontology YAML loader on libyaml (CSafeLoader). - Skip the 3.5 s clock-read retry backoff in the stub runtime, give offline Temporal replayers a build_id, and use short timeouts in the JWKS, readyz and logger overflow tests (production values are still asserted). No real latency in the Drive perf test. - Worker-runner tests no longer start the health server on the fixed port 8001. - Fixed UUID in the bad-cursor parametrize ids: a random one made every xdist worker collect different tests. - Add pytest-xdist; make unit-test runs -n auto --dist loadfile. Local (macOS): serial 13m38s -> 6m32s, 4 workers 2m14s; 13,683 passed, same as before.
akozak-gd
approved these changes
Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The CI job Unit (python services) took 20-28 min of pytest in recent runs; every other job takes 8 min or less. An audit of all 532 backend test files (14,512 cases) showed that the time does not come from a few slow tests: deleting every low-value test would save under a minute. It comes from work repeated in thousands of tests, a few real waits, and the serial run.
What changes
Ontology,PlanRules,GapRulesand the shop models are frozen, so sharing is safe. The ontology loader is based onyaml.CSafeLoader(libyaml, about 10x faster); duplicate keys are still rejected with their line. This is the onlysrc/change.build_id(the first replay hashed every loaded module, about 4.7 s); the JWKS, readyz and logger-overflow tests use short timeouts and still assert the production values; the Drive perf test computes the 300 ms-per-call bound instead of sleeping it.uuid4()in the bad-cursor parametrize ids made each xdist worker collect different tests, which aborts the run; it is now a fixed UUID. The worker-runner tests no longer start the health server on the fixed port 8001 (the health test that needs it restores the real server).pytest-xdistin the dev group;make unit-testrunspytest -n auto --dist loadfile(each file stays in one process, so module fixtures load once). A plainuv run pytest <file>is unchanged.How it was checked
Local, macOS (the CI runner is slower, so the CI time of this PR is the real number):
13,683 passed in every run, the same count as before. The only failures are the 3 known macOS-only process-group tests in
test_mcp_qa_lib.py(os.pidfd_open), which pass on Linux.make checkand the Python validation tracks (validate-python-lint,-scripts,-arch,validate-licences) pass.Follow-ups