Skip to content

Isolate test_dictionaries_all_layouts_separate_sources dictionary configs per worker - #103837

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-test-dictionaries-worker-isolation
May 1, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-test-dictionaries-worker-isolation

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented May 1, 2026 •

Copy link
Copy Markdown
Member

In Integration tests (..., targeted) and flaky-check jobs, every pytest-xdist worker runs the same test module concurrently with its own isolated ClickHouseCluster. Cluster project names and instance directories already include the worker id (e.g. -gw0), but BaseLayoutTester.get_dict_directory returned a single worker-shared path:

tests/integration/test_dictionaries_all_layouts_separate_sources/
    configs/dictionaries/<test_name>/

Multiple workers therefore raced on cleanup, create_dictionaries, and list_dictionaries for the same on-disk directory. A typical losing interleaving:

  1. Worker A writes its dictionary XMLs.
  2. Worker B's simple_tester.cleanup calls shutil.rmtree on the same directory.
  3. Worker A's started_cluster calls simple_tester.list_dictionaries, which now sees only Worker B's partially-written files (or none at all).
  4. Worker A's cluster starts without the expected dictionaries, and dictGet('MongoDB_<layout>_', ...) later fails server-side with Code: 36. DB::Exception: Dictionary (MongoDB_direct_) not found.

CIDB shows this pattern across test_mongo.py::test_simple_ssl[*-True] (direct/cache/hashed/flat) failing together in Integration tests (amd_asan_ubsan, targeted) runs — characteristic of a shared-setup race, not a per-test bug.

Fix: append PYTEST_XDIST_WORKER to the dictionary directory name (mirroring how ClickHouseCluster already isolates its project_name and instances_dir_name), so each worker writes to its own directory and the race goes away. When the env var is unset (single-worker local runs), the path is unchanged.

Follow-up to #102734.

Changelog category (leave one):

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

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.5.1.238

…figs per worker

When `Integration tests (..., targeted)` or flaky-check jobs run, the integration
test runner uses `--dist=each`, which makes every pytest-xdist worker execute
the same test module concurrently with its own isolated `ClickHouseCluster`.
Cluster project names and instance directories already include the worker id
(e.g. `-gw0`), but `BaseLayoutTester.get_dict_directory` returned a single
worker-shared path:

    tests/integration/test_dictionaries_all_layouts_separate_sources/
        configs/dictionaries/<test_name>/

Multiple workers therefore raced on `cleanup`, `create_dictionaries`, and
`list_dictionaries` for the same on-disk directory. A typical losing
interleaving:

  1. Worker A writes its dictionary XMLs.
  2. Worker B's `simple_tester.cleanup` calls `shutil.rmtree` on the same dir.
  3. Worker A's `started_cluster` calls `simple_tester.list_dictionaries`,
     which now sees only Worker B's partially-written files (or none at all).
  4. Worker A's cluster starts without the expected dictionaries, and
     `dictGet('MongoDB_<layout>_', ...)` later fails server-side with
     `Code: 36. DB::Exception: Dictionary (MongoDB_direct_) not found.`

CIDB shows this pattern across `test_mongo.py::test_simple_ssl[*-True]`
(direct/cache/hashed/flat) failing together in `Integration tests
(amd_asan_ubsan, targeted)` runs.

Fix: append `PYTEST_XDIST_WORKER` to the dictionary directory name (mirroring
how `ClickHouseCluster` already isolates its `project_name` and
`instances_dir_name`), so each worker writes to its own directory and the
race goes away. When the env var is unset (single-worker local runs), the
path is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e25922f]

Summary: ✅


AI Review

Summary

This PR isolates dictionary config directories per pytest-xdist worker in an integration test helper by appending PYTEST_XDIST_WORKER to the per-test directory name, which directly addresses a real concurrent-worker race in targeted/flaky CI runs. The change is narrow, preserves single-worker behavior, and is safe.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 1, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this May 1, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 1, 2026
Merged via the queue into master with commit 43269bb May 1, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-test-dictionaries-worker-isolation branch May 1, 2026 15:41
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants