Skip to content

Parallelize test execution using xdist - #720

Open
koletzilla wants to merge 7 commits into
mainfrom
ClickHouse/parallel-integration-tests-main
Open

Parallelize test execution using xdist#720
koletzilla wants to merge 7 commits into
mainfrom
ClickHouse/parallel-integration-tests-main

Conversation

@koletzilla

@koletzilla koletzilla commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Test users (the DBT_TEST_USER problem)

  • Before: the three test users were created once, at the start of the whole test session, and their names were passed around through environment variables. This broke with parallel runs.
  • Now: each test class that actually needs users creates its own three users, with random unique names, right before the class runs, and drops them when the class is done. The environment variables are still set (upstream dbt tests require them), but only for the duration of that class, and they are restored afterwards.
  • Only the grants and dbt_clone test folders need users, so each of those folders got a tiny new conftest.py that turns this on. Everyone else never pays for it.

Docker handling

  • Sequential runs (the old default) still work exactly as before: set DBT_CH_TEST_USE_DOCKER and the test session starts and stops the ClickHouse cluster for you.
  • Parallel runs must start the cluster themselves first (docker compose up -d). If you try to combine DBT_CH_TEST_USE_DOCKER with -n, you get a clear error explaining what to do instead of a confusing failure.
  • CONTRIBUTING.md now documents both ways of running the tests.

Making tests safe to run at the same time

  • Each test gets a schema name that includes the worker id plus a random suffix, so two workers can never step on each other's tables.
  • SYSTEM FLUSH LOGS runs once per worker at startup, so system tables exist before tests query them.
  • pytest.ini: makes pytest's doctest collector to skip conftest.py files (having several files with the same name broke imports).

CI (GitHub Actions)

  • The workflows now start the ClickHouse cluster as their own step, then run pytest with -n 5 --dist loadscope --timeout=300 for both the HTTP and native test jobs. pytest-xdist was added to dev_requirements.txt.

Adapter fixes for flaky tests found by running in parallel

  • New shared helper retry_on_database_error in util.py.
  • dbclient.py: command() and get_ch_setting() can now retry transient failures internally (the drivers implement the raw _command / _get_ch_setting versions). A failed check of the allow_nondeterministic_mutations setting is no longer cached for the whole process. Before, one bad read silently disabled lightweight deletes for every later connection in that process. Warning messages now say clearly what got disabled and show the real error.
  • nativeclient.py: reading a setting now raises a proper error instead of returning None, which used to crash with a confusing message.

ClickHouse test cluster config (test_config.xml)

  • Keeper election timings widened (heartbeat 1s, election window 4–8s): all three keeper nodes share one machine with the test workers, and short CPU stalls were triggering pointless leader elections that killed in-flight ON CLUSTER statements (the "Code 999" flake).
  • The distributed DDL queue now cleans itself up (finished tasks kept 5 minutes instead of 7 days, cleanup every 15s instead of 60s): before, the queue filled up to its 1000-task cap and stayed there forever, causing sporadic timeouts.

@koletzilla
koletzilla force-pushed the ClickHouse/parallel-integration-tests-main branch from 8923da5 to e69480e Compare August 24, 2026 09:18
- Increase max_tasks_in_queue as for some high concurrency loads (-n 10, 3 consecutive runs) this may be still reached
@koletzilla
koletzilla force-pushed the ClickHouse/parallel-integration-tests-main branch from e69480e to 0b64e6a Compare August 24, 2026 17:37
@koletzilla
koletzilla marked this pull request as ready for review August 24, 2026 18:04
@koletzilla
koletzilla requested a review from mzitnik August 24, 2026 18:04
from dbt.tests.util import run_dbt

oom_table_sql = """
SELECT a FROM system.numbers_mt GROUP BY repeat(toString(number), 100000) as a

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This query was ok if run sequentially. If other run at the same time, it caused OOMs in the replica, making the rest of the tests to fail

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0b64e6a. Configure here.

Comment thread tests/integration/conftest.py
@koletzilla koletzilla changed the title Change conftest to be able to parallelize tests using xdist Parallelize test execution using xdist Aug 25, 2026
@koletzilla

Copy link
Copy Markdown
Contributor Author

One tests if failing in a flaky way. Fixing would require a few changes so I have created an issue to track it #724

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