Skip to content

The unit job runs the suite on every core with pytest-xdist - #287

Merged
zlareb1 merged 13 commits into
mainfrom
ci/unit-xdist
Nov 6, 2026
Merged

zlareb1 merged 13 commits into
mainfrom
ci/unit-xdist

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

...

Why

pytest unit + coverage ran 27,510 tests in one process: the pytest step took 44 minutes of the job's 45-minute timeout on main. The runner's second core sat idle. pytest-xdist runs one worker per core; pytest-randomly passes the same seed to every worker, so the order is still random and the seed is still printed, and pytest-cov combines the workers' data into the same coverage.json the floors gate reads.

Running in parallel exposed four tests that depended on a quiet machine or on collection being random, and a wall-clock bound in the extraction tests (below). Each is fixed at its source:

Test What raced Fix
test_request_ids.py::test_a_short_token_is_used_as_sent its id came from uuid4() at collection, and xdist refuses workers whose collections differ a fixed UUID literal
test_cli_child_stop.py::test_a_cancelled_wait_stops_the_child_and_its_children when the pid file already existed, the test cancelled the task before its first step, so wait_or_stop never ran and nothing reaped the child await asyncio.sleep(0) after create_task, so the wait is running before it is cancelled
test_shutdown_deadline.py::test_the_process_exits_without_waiting_on_a_stuck_heartbeat the 5 s bound covered the child interpreter's start and imports as well as the exit the child prints time.monotonic() just before retire_process, and the parent measures from that moment to the exit (CLOCK_MONOTONIC is one clock for every process on the host); the 5 s bound is unchanged
test_workers_child.py::test_the_child_dies_with_its_parent a fixed 1 s sleep stood in for "the grandchild has set its death signal" the grandchild writes its pid after die_with_parent(), and the parent is killed only after that

--durations=30 lists the slowest tests at the end of the job. One -v run, which names each result's worker, took 41:27 against 29:39 and 32:05 for -q; with one sample the cause is not settled (the same run was slow on a CPU-bound test too), and the job keeps -q; tests/README.md says how to find a neighbour without the worker's sequence.

Scope and risk

CI configuration, the make test-unit and make test-unit-cov targets, the pytest-xdist dev dependency (pyproject.toml, uv.lock), five test files (the four races, and the extraction tests' bounds now on CPU time, which test_document_extraction_tables.py also gets through its import of _within), and the testing docs, the tests rule, two skills and CONTRIBUTING.md. No server code changes. A test that shares a file, port or directory with another test can now fail when the two run at once. The full suite passed under -n 16 and -n 8, with a different seed for each run, apart from the case below, and the testing docs now state the rule.

test_document_extraction_tables.py::test_the_delimiter_is_sniffed_in_bounded_time fails on the development host with or without xdist: csv.Sniffer spends 7 to 16 s of CPU there (an aarch64 host, without coverage) on its 64 KiB sample, over the test's 5 s bound, so the time is CPU work, not load from other tests. It passes on CI's x86-64 runners with coverage on; why the sniffer is that much slower on aarch64 is outside this PR. Its bound now counts CPU time through _within and is otherwise unchanged. test_document_extraction.py::test_one_line_sql_with_a_comment_after_every_semicolon_splits_in_bounded_time took 11.7 s against its 10 s bound in the -v run (1.6 s on the development host without coverage). With a second worker on the runner's other core, wall time counts that worker's load against every such bound, so _within, the timer of the extraction tests' bounded-time checks (12 calls in two files), and the timer of test_the_wide_integer_check_is_linear_in_a_deep_table_of_long_keys now measure the process's CPU time (time.process_time()). The bounds are unchanged, and a loop that turned quadratic still spends its minutes of CPU.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none.
  • Rollback: revert; the job runs in one process again.

Tests

Measured on this PR's CI runs at 54fed4c and 0880052 (the later commits change test timers, docs and comments, not the job's command): the pytest step took 29:39 (27,510 passed, 20 skipped, 1 xfailed, the counts on main), down from 44:04, and the job 30:45 at 54fed4c and 32:05 at 0880052. The repository's runners have two cores, so -n auto starts two workers. Splitting the suite across runners is the next step, in its own PR.

Coverage is unchanged. main's CI coverage.xml had lines 178,318 / 192,923 and branches 46,727 / 54,912. This branch under -n 8 has lines 178,323 / 192,923 and branches 46,732 / 54,912. The 5-line difference is environment-dependent skips on the development host. python -m tests.inventory.coverage_floors coverage.json passes.

pytest tests/unit -q -n 8 -p randomly --randomly-seed=777 --cov=server --cov=sdk/python/loom --cov-branch --cov-report=json:coverage.json
python -m tests.inventory.coverage_floors coverage.json

Test count is unchanged: CI's run reports 27,510 passed, 20 skipped and 1 xfailed, the same 27,531 as main's run. This PR adds no test and removes none.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. The author checked the coverage totals, the floors and each race's cause.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass, apart from the delimiter-sniff test named above, which fails on the development host's CPU and passes on CI's runners; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version.
  • The frontend builds and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

🤖 Generated with Claude Code

zlareb1 and others added 5 commits November 6, 2026 13:16
The single-process run took 44 of its 45 minutes. Three tests that raced a slow process start under load now wait on the event they check, and one parametrize id no longer comes from uuid4(), which every xdist worker must collect identically.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…on advice

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… and the grandchild's cleanup

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…er's sequence in the CI log

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…t link to, the pid wait reads once

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
zlareb1 and others added 8 commits November 6, 2026 14:48
…nute run

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…production keeps randomly's per-test seeds, one pid reader

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… pre-push timing is CI's measured one, a shorter _within docstring

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ved its parent

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit a523d49 into main Nov 6, 2026
27 of 28 checks passed
@zlareb1
zlareb1 deleted the ci/unit-xdist branch November 6, 2026 17:24
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