FXC-4725: Fix flaky xdist failures in async web tests #3134
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.
Fixes intermittent
h5pyfile-locking errors under xdist when multipletest_asynccases callrun_asyncwith the defaultpath_dir=".", causing concurrent writes to./batch.hdf5.Changes:
path_dir=str(tmp_path)torun_asyncin async web tests so each worker writes to an isolated directory.Checks:
poetry run pytest -q --no-cov -W ignore tests/test_web/ --maxfail=1Note
Addresses xdist flakiness by isolating async test artifacts per worker.
test_webapi*.pyto passpath_dir=str(tmp_path)torun_asynctmp_pathfixture to correspondingtest_asyncsignaturesWritten by Cursor Bugbot for commit f1a54c1. This will update automatically on new commits. Configure here.
Greptile Summary
This PR fixes flaky xdist failures in async web tests by isolating test artifacts per worker. The issue occurred when multiple test workers concurrently called
run_asyncwith the defaultpath_dir=".", causing concurrent writes to the same./batch.hdf5file and h5py file-locking errors.Changes: All five async test functions (
test_asyncintest_webapi.py,test_webapi_eme.py,test_webapi_heat.py,test_webapi_mode.py, andtest_webapi_mode_sim.py) now:tmp_pathpytest fixture parameterpath_dir=str(tmp_path)torun_async()callsThis ensures each test worker writes to its own isolated temporary directory, preventing file contention and flaky failures under parallel test execution.
Confidence Score: 5/5
tmp_pathfixture as recommended by the custom instruction rule 6efa8f43. No logic changes, no API changes, and no side effects to existing functionality.Important Files Changed
tmp_pathfixture totest_asyncfunction signature and passedpath_dir=str(tmp_path)torun_async()call to isolate async test artifacts to temporary directory per worker.tmp_pathfixture totest_asyncfunction signature and passedpath_dir=str(tmp_path)torun_async()call to isolate async test artifacts to temporary directory per worker.tmp_pathfixture totest_asyncfunction signature and passedpath_dir=str(tmp_path)torun_async()call to isolate async test artifacts to temporary directory per worker.tmp_pathfixture totest_asyncfunction signature and passedpath_dir=str(tmp_path)torun_async()call to isolate async test artifacts to temporary directory per worker.tmp_pathfixture totest_asyncfunction signature and passedpath_dir=str(tmp_path)torun_async()call to isolate async test artifacts to temporary directory per worker.Sequence Diagram
sequenceDiagram participant Worker1 as Test Worker 1 participant Worker2 as Test Worker 2 participant tmpPath as tmp_path Fixture participant runAsync as run_async participant batchFile as batch.hdf5 Worker1->>tmpPath: Get isolated tmp_dir_1 Worker2->>tmpPath: Get isolated tmp_dir_2 Worker1->>runAsync: run_async(..., path_dir=tmp_dir_1) Worker2->>runAsync: run_async(..., path_dir=tmp_dir_2) runAsync->>batchFile: Write to tmp_dir_1/batch.hdf5 runAsync->>batchFile: Write to tmp_dir_2/batch.hdf5 Note over Worker1,Worker2: No file contention - isolated directoriesContext used:
dashboard- Utilize standard pytest fixtures like tmp_path (for files) and monkeypatch (for mocking state or imp... (source)