Repository navigation
Fix flaky test_s3_cluster: scope generated CSV dir per xdist worker - #104020
alexey-milovidov merged 1 commit into
Conversation
The `started_cluster` fixture writes 100 CSV files to `tests/integration/test_s3_cluster/data/generated/` and uploads them to MinIO, then deletes the directory in teardown. Under `Integration tests (amd_asan_ubsan, targeted)` the runner uses pytest-xdist with `--dist=each`, so multiple workers execute the fixture in parallel. Their MinIO containers are isolated by `ClickHouseCluster` (it appends `PYTEST_XDIST_WORKER` to `project_name`), but the host filesystem path was shared. One worker's teardown could `shutil.rmtree(...)` the directory while another worker was still iterating over it inside the upload loop, surfacing as `FileNotFoundError: data/generated/file_0.csv` during fixture setup and failing every test in the module. Tracked as Issue ClickHouse#102238 since 2026-04-09 (open). Scope the host directory by `PYTEST_XDIST_WORKER` so concurrent workers no longer share filesystem state. The MinIO bucket key still uploads under the canonical `data/generated/` prefix, so tests querying `http://minio1:9001/root/data/generated/*` are unchanged. Also decouple the host path from the bucket key (previously a single `f"data/generated/file_{n}.csv"` was used as both), drop the module-level mutable `S3_DATA` list, and guard `cluster.shutdown()` in the teardown against the case where `ClickHouseCluster(__file__)` itself raises before binding `cluster`. Race deterministically reproduced with a minimal Python harness (2 threads, shared dir, 20/20 trials hit FileNotFoundError; with per-worker dirs, 0/20). Closes ClickHouse#102238
|
Session ID: cron:clickhouse-ci-task-worker:20260504-161500 Pre-PR validation gate
Self-review against
|
|
cc @azat @maxknv — could you review this? It scopes test_s3_cluster's host-side |
|
@fm4v, what was the idea behind --dist=each? I think we have more tests that cannot run concurrently with themselves. |
|
Workflow [PR], commit [05d7953] Summary: ✅ AI ReviewSummaryThis PR fixes a real integration-test race in Missing context
ClickHouse Rules
Final Verdict
|
|
@maxknv it's described in #100181 Before (#66986): flaky check used After (#100181): Overall it stabilized the flaky check: |
alexey-milovidov
left a comment
There was a problem hiding this comment.
The general idea is reasonable.
The
started_clusterfixture intests/integration/test_s3_cluster/test.pywrites 100 CSV files to
tests/integration/test_s3_cluster/data/generated/,uploads them to MinIO, then deletes the directory in teardown.
Under
Integration tests (amd_asan_ubsan, targeted)the runner usespytest-xdist with
--dist=each, so every test goes to every worker and themodule-scoped fixture runs concurrently in multiple processes. Their MinIO
containers are isolated by
ClickHouseCluster(it appendsPYTEST_XDIST_WORKERtoproject_name), but the host filesystem path wasshared. One worker's teardown could
shutil.rmtree(...)the directorywhile another worker was still iterating over it inside the upload loop in
create_buckets_s3, surfacing asFileNotFoundErrorondata/generated/file_0.csvduring fixture setup and failing every test inthe module via fixture error.
Pattern matches Issue #102238 (open since 2026-04-09) and CIDB shows ~21–23
unrelated PRs hitting the same setup error in the past 30 days for tests
across the suite (
test_wrong_cluster,test_select_all,test_count,test_union_all,test_hive_partitioning, etc.) — exactly the symptomexpected when a module-scoped fixture errors and propagates to all 18
tests.
Earlier PR #102144 added
ignore_errors=Trueto the teardownrmtreetosilence the cleanup-side variant of this race; this change addresses the
upload-side variant by removing the shared resource.
This change scopes the host directory by
PYTEST_XDIST_WORKERsoconcurrent workers no longer share filesystem state. The MinIO bucket key
still uploads under the canonical
data/generated/prefix, so all testqueries (
SELECT … FROM s3('http://minio1:9001/root/data/generated/*'…))are unchanged. Also decouple the host path from the bucket object key
(previously a single
f"data/generated/file_{n}.csv"was used as both),drop the module-level mutable
S3_DATAlist, and guardcluster.shutdown()in the teardown against the pre-existing case wherethe
ClickHouseCluster(__file__)constructor raises beforeclustergetsbound.
Race deterministically reproduced with a minimal Python harness
(
tmp/race_repro.py, 2 threads, shared dir): 20/20 trials hitFileNotFoundErrorwithout the fix; 0/20 with per-worker dirs.Closes #102238
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Version info
26.5.1.291