CI: --dist loadscope in ci.yml and added test_xdist_isolation - #736
Conversation
|
| Filename | Overview |
|---|---|
| .github/workflows/ci.yml | Adds --dist loadscope to the parallel pytest invocation so module tests execute on the same worker. |
| tests/integration/test_xdist_isolation.py | Adds integration coverage for module-local OpenTelemetry state and a fresh module-scoped in-memory DuckDB backend; the previously reported cross-run stale-row issue is fixed. |
| .claude/rules/release.md | Updates the documented CI test command to include the new xdist distribution strategy. |
Reviews (7): Last reviewed commit: "Merge branch 'main' into speed-up-tests" | Re-trigger Greptile
|
@sujalgawas thanks for the careful work here, and especially for the repeat runs and screenshots. Your diagnosis of why I ran both arms in a scratch worktree on identical product code, warm caches, same test set with your new file excluded from both: So Also relevant: issue #651 is partly stale. It says "no pytest-xdist, no -n", but On the new test file, three problems: 1. 2. It passes on stale state. Rows accumulate across runs. After two runs the file held 16 rows; I then ran 3. It hard-codes ~2.9s of You flagged the uncertainty yourself in the body ("its on maintainers if its valid to have this test or not"), which I appreciate. My answer: the What I'd merge:
One note in your favor that I couldn't fully confirm: Your job names and the four required contexts are byte-identical to main, so branch protection is safe. I checked that before anything else. |
|
|
@sujalgawas the rewrite fixed the things that mattered — thanks for turning it around. The shared I also owe you a correction. I said the new test only exercises pytest's scheduler and not TokenJam. That's literally true, but I framed it as a reason to drop the test, and I was wrong about the conclusion. The pattern it simulates is real in this repo: there are 13 module- and session-scoped fixtures across 9 files, including So the change should land. The framing is what needs fixing, not the change. The measurement still stands, for the record — warm caches, same test set, both arms:
What's left, all small:
None of that is structural. Do those and I'll merge it. One more thing worth flagging, since you'd hit it: merging this pins CI to a flag that your test requires. If someone later removes |
|
made the requested change. I was trying to change the branch name but it just kept getting deleted thats why the PR is closed and opened mutliple times sorry for that. |
|
no worries. thanks for the updates and for the contribution @sujalgawas - reviewing and merging now |
anilmurty
left a comment
There was a problem hiding this comment.
Thanks @sujalgawas — merging. You addressed every point, and the module docstring note is better than what I asked for: telling the next person that a --dist change will surface here as four product-looking failures will save someone real time.
Verified before merging rather than trusting the green checks:
ruff checkon the file is clean — all four unused imports gone, along with the deaddbfixture and the no-op_init_shared_db.- The test still discriminates: 10 passed under
--dist loadscope, 2 failed under--dist load. A rewrite that quietly stopped proving anything was the main risk here, and it doesn't. - Full suite under the new flag: only the three known
summarizefailures that also occur on main under an isolated HOME. Nothing new. - This CI run genuinely exercised the change, since
ci.ymlcomes from the branch onpull_request— so the flag is proven in the real job, not just locally.
The reframe is the part that matters most. "Fixture-scoping correctness" is the justification that survives someone benchmarking this later and finding no speedup; "speed up CI" would have gotten it reverted. Thanks for taking that on rather than defending the original framing.
One cosmetic leftover, not worth another round: test_duckdb_concurrent_writer_lock still has "lock" in its name, though there's no file lock anymore. Rename it if you touch the file again.
Summary
Closes #651
Updated the CI pytest command to use
--dist loadscopewith pytest-xdist.The reason for using
--dist loadscopeis fixture-scoping correctness and test isolation, rather than a CI speed improvement.Some tests use module-scoped fixtures. When pytest-xdist distributes tests across workers, tests that rely on the same module-scoped fixtures can be distributed in a way that causes the fixtures to be instantiated separately across workers.
Using:
keeps tests from the same module together on the same worker, which preserves the expected module-level fixture scope and avoids the isolation issues demonstrated by
test_xdist_isolation.py.I also added
test_xdist_isolation.pyto demonstrate why--dist loadscopeis needed when running these tests in parallel.I did not use
xdist-groupbecause the relevant isolation requirement is at the module/fixture scope.pytest-xdistwas already included in[dev], so no dependency changes were necessary.Testing
The following command was run multiple times to verify the behavior:
The same test suite was also run without
--dist loadscopeto demonstrate the difference in behavior:pytest -n auto --dist loadscope tests/unit/ tests/synthetic/ tests/agents/ tests/integration/pytest -n auto tests/unit/ tests/synthetic/ tests/agents/ tests/integration/after creating
test_xdist_isolation.pypytest -n auto --dist loadscope tests/unit/ tests/synthetic/ tests/agents/ tests/integration/pytest -n auto tests/unit/ tests/synthetic/ tests/agents/ tests/integration/Checklist
pytest tests/unit/ tests/synthetic/ tests/agents/ tests/integration/)ruff check tokenjam/)mypy tokenjam/)tests/factories.py(not rawNormalizedSpan)@anilmurtyas reviewer (or @-mentioned him above)