Skip to content

Skip CI batches when only test files changed and none fall in the batch - #109668

Merged
maxknv merged 8 commits into
masterfrom
ci-skip-batches-test-only-changes
Jul 9, 2026
Merged

maxknv merged 8 commits into
masterfrom
ci-skip-batches-test-only-changes

Conversation

@maxknv

@maxknv maxknv commented Jul 7, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

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

functional_tests.py and integration_test_job.py already split the full test suite across parallel N/M batches. When a PR only touches test files (no production or CI-job code), most batches would produce results identical to master, since only the batch(es) containing the actually changed tests can differ.

Both jobs now check Info().get_changed_files() (populated by the CI store_data.py pre-hook) and, when every changed file is a recognized tests/queries/0_stateless or tests/integration/test_* test file (or a change under ci/jobs/), skip a batch outright if none of the changed tests are assigned to it:

  • for functional tests, by reusing the same crc32(filename) % total_batches hash-batching formula that clickhouse-test itself uses;
  • for integration tests, by checking membership in the already-computed get_optimal_test_batch module assignment for the current batch.

If none of the batches contain a changed test at all (e.g. only test files of the other job type changed), the job is skipped entirely.

The shared file-classification and hash-bucket-resolution helpers are added as static/class methods on Targeting (ci/jobs/scripts/find_tests.py) so both job scripts and the pre-existing changed_test_modules logic in integration_test_job.py reuse the same predicates instead of duplicating them.

Also includes a handful of unrelated grammar fixes in test file comments, used to produce a real test-only diff to validate the new logic end-to-end.

Version info

  • Merged into: 26.7.1.708 (included in 26.7 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e33ad46]

Summary: ✅


AI Review

Summary

This PR teaches the stateless and integration runners to skip shards when a PR only changes tests, and it skips the final LLVM Coverage merge when the build looks unchanged. The optimization is reasonable, but the current predicates still over-assume that skipped shards are equivalent to master: several realistic PR shapes can skip shards whose workload or binary is different, so I would not merge this as-is.

Findings

⚠️ Majors

  • [ci/jobs/functional_tests.py:347, ci/jobs/integration_test_job.py:904] [dismissed by author -- https://github.com/Skip CI batches when only test files changed and none fall in the batch #109668#discussion_r3537620338] Treating any ci/jobs/** file as "test-only" lets runner-only PRs escape same-family execution. I still consider this real because a pure CI-script PR, or ci/jobs/functional_tests.py plus only integration tests, still hits the changed_functional_files == [] skip path before any stateless tests are selected; the integration runner has the mirror changed_integration_modules == [] case.
  • [ci/jobs/functional_tests.py:340, ci/jobs/integration_test_job.py:893] [dismissed by author -- https://github.com/Skip CI batches when only test files changed and none fall in the batch #109668#discussion_r3545816432] is_ci_job_script also whitelists build-affecting CI files such as ci/jobs/build_clickhouse.py and ci/jobs/scripts/job_hooks/build_profile_hook.py. I still consider this real because those files are inputs to the build digest, so these jobs can skip every shard that does not contain the edited test even though the produced binary is different from master.
  • [ci/jobs/integration_test_job.py:899-916] [dismissed by author -- https://github.com/Skip CI batches when only test files changed and none fall in the batch #109668#discussion_r3543111858] The membership check assumes adding or removing one integration module leaves the other batch assignments unchanged, but get_optimal_test_batch repacks whole prefixes by duration. On the current suite, adding test_zookeeper/test_added_module.py moves existing test_zookeeper_* modules across six of eight batches, so "changed module not in this batch" is not equivalent to "same workload as master."
  • [ci/jobs/functional_tests.py:367-378] The parallel/sequential pruning only looks at the PR version of each changed file. If a patch changes a test's own Tags: line and moves it between the parallel and sequential halves, the old half can be skipped even though master still runs the modified file there.
  • [ci/jobs/scripts/workflow_hooks/filter_job.py:83-96, 403-407] _has_build_digest_changes does not match Praktika's real build digest: Digest.calc_job_digest also hashes the build job config and Docker digest. A ci/defs/job_configs.py or build-image change can therefore alter the build while this helper still returns false and suppresses the LLVM Coverage merge/report job.
Tests
  • ⚠️ Add focused regression coverage for the cases above: CI-script-only PRs, build-affecting CI-script plus one changed test, integration add/remove-module PRs, and a stateless test whose Tags: move it between the parallel and sequential halves.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: stop treating arbitrary ci/jobs/** changes as equivalent to test-only diffs, and make the skip decisions compare against the real workload or build boundary (master batch assignment, old/new sequential classification, real build digest) before skipping shards.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 7, 2026
Comment thread ci/jobs/scripts/find_tests.py Resolved
functional_tests.py and integration_test_job.py already split the full
test suite across parallel N/M batches. When a PR only touches test files
(no production or CI-job code), most batches would produce results
identical to master, since only the batch(es) containing the actually
changed tests can differ. Both jobs now check Info().get_changed_files()
(populated by the CI store_data.py pre-hook) and, when every changed file
is a recognized tests/queries/0_stateless or tests/integration/test_* test
file (or a change under ci/jobs/), skip a batch outright if none of the
changed tests are assigned to it - reusing clickhouse-test's own
crc32(filename) % total_batches hashing for functional tests and the
existing get_optimal_test_batch module assignment for integration tests.

The shared file-classification and hash-bucket-resolution helpers are added
as static/class methods on Targeting (ci/jobs/scripts/find_tests.py) so both
job scripts and the existing changed_test_modules logic reuse the same
predicates instead of duplicating them.

Also fixes a handful of unrelated grammar typos in test file comments, used
to validate the new logic end-to-end against a real test-only diff.
@maxknv
maxknv force-pushed the ci-skip-batches-test-only-changes branch from 7f0e3cf to 515118b Compare July 7, 2026 19:02
Comment thread ci/jobs/scripts/find_tests.py Resolved
Coverage numbers only move when the compiled binary changes, so a PR that
only touches tests, docs, or CI scripts produces a merge report identical
to master. `should_skip_job` now skips `JobNames.LLVM_COVERAGE` on PRs
whenever none of the changed files fall under `build_digest_config`'s
include paths (the same paths that gate the build job's own cache digest
in `ci/defs/job_configs.py`), via a new `_has_build_digest_changes` helper.

This supersedes the narrower "only ci/*.py changed" special case that
previously gated this job: that check also incorrectly skipped coverage
when `ci/jobs/build_clickhouse.py` or `build_profile_hook.py` changed even
though those files are themselves part of the build digest.
maxknv added 2 commits July 8, 2026 10:22
`parallel`/`sequential` is a second, independent sharding dimension used by
some stateless test job flavors (e.g. `amd_tsan, parallel, 1/2` vs
`amd_tsan, sequential, 1/2`): each flavor hashes and batches its own subset
of tests (`--no-sequential`/`--no-parallel`), and a test tagged `no-parallel`
or `sequential` never runs under the "parallel" flavor (and vice versa),
regardless of batch number.

The batch-skip check added in the previous commit ignored this and only
looked at the crc32 hash bucket, so a changed test could be judged
"in this batch" for a job flavor that would never even select it. Add
`Targeting.is_sequential_functional_test` (mirrors `clickhouse-test`'s own
`Tags:`-based `is_sequential_test` classification) and use it to restrict
the changed-file set to what the current job's parallel/sequential flavor
would actually run before doing the hash-bucket check.

Also stop gating the whole check on `total_batches > 1`: some parallel/
sequential flavors have no batch number at all (e.g. `amd_debug, parallel`),
but the flavor-applicability check (skip the whole job if none of the
changed tests apply to this flavor) is still valid without batching. Only
the crc32 hash-bucket sub-check needs `batch_num and total_batches > 1`
(also avoids a `% 0` when there is no "N/M" token).
The batch-skip check excluded is_llvm_coverage runs, but coverage numbers
for a batch are just as unaffected by a test-only change as any other
batch: if no production code changed, a skipped llvm_coverage batch is
identical to master's, and the final merge job already knows to supplement
missing profdata from master (see the coverage sub-job skipping logic in
filter_job.py). Drop the exclusion in both functional_tests.py and
integration_test_job.py so coverage batches benefit from the same skip.
@maxknv
maxknv force-pushed the ci-skip-batches-test-only-changes branch from cd8261a to a0e2d74 Compare July 8, 2026 09:58
Comment thread ci/jobs/functional_tests.py Resolved
Comment thread ci/jobs/functional_tests.py Resolved
Comment thread ci/jobs/integration_test_job.py Resolved
@maxknv

maxknv commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

requires #109250

Comment thread ci/jobs/functional_tests.py Resolved
Comment thread ci/jobs/scripts/find_tests.py Resolved
Comment thread ci/jobs/integration_test_job.py Resolved
maxknv added 2 commits July 8, 2026 18:33
clickhouse-test only treats files directly inside the suite root as test
cases for --run-by-hash-* bucketing (is_test_from_dir/get_selected_tests use
os.listdir, not recursive). A nested file like
tests/queries/0_stateless/helpers/httpclient.py or
tests/queries/0_stateless/data_avro/generate_avro.sh previously resolved to
a fabricated hash-batch identity based on its basename, letting a helper- or
fixture-only change skip most batches while real dependent tests went unrun.

Require the parent directory to be exactly the suite root before attempting
direct-hit or sibling-test resolution; otherwise return None so the caller
conservatively runs the batch.

Reported by review on #109668:
#109668 (comment)
Comment thread ci/jobs/functional_tests.py Resolved
…stead of just checking membership

Move the batch-skip check to after the is_sequential/is_parallel handling
so it operates on the modules this job invocation will actually run, not
the pre-flavor-filter set.

Most real integration test job configs run parallel_test_modules and
sequential_test_modules together in one invocation (no explicit
parallel/sequential option). For those, checking mere set membership only
let us skip the whole batch when neither side contained a changed module.
Now, when only one side contains a changed module, drop the other side
entirely (it would produce results identical to master) instead of running
it anyway - a real time saving even when the batch itself is not skipped.

Addresses review comment on #109668:
#109668 (comment)
Comment thread ci/jobs/functional_tests.py Resolved
@ClickHouse ClickHouse deleted a comment from clickhouse-gh Bot Jul 9, 2026
@maxknv
maxknv added this pull request to the merge queue Jul 9, 2026
Merged via the queue into master with commit e7c1f02 Jul 9, 2026
175 checks passed
@maxknv
maxknv deleted the ci-skip-batches-test-only-changes branch July 9, 2026 12:29
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 9, 2026
Bartok9 pushed a commit to Bartok9/ClickHouse that referenced this pull request Jul 27, 2026
…merge job

`should_skip_job` already skipped the `LLVM_COVERAGE` merge job when a PR had
no build-digest-affecting changes, but the `amd_llvm_coverage` test-shard
batches and the coverage build still ran - burning CI time producing profdata
that the (already-skipped) merge job would never consume. ClickHouse#109668 made this
worse by also skipping only some batches within those jobs based on a
per-batch hash-bucket check, so a tests-only PR ended up with an inconsistent
mix of some batches running and others skipped.

Extend the existing `ci-no-coverage` label condition (which already skips the
build, all `amd_llvm_coverage` shards, `excluded_from_llvm` jobs, and the
merge job together) to also fire automatically whenever the PR has no
build-digest changes. This makes the skip consistent (the whole family or
none of it) and removes the now-dead single-test-type sub-job skip block and
the standalone merge-job-only skip, both superseded by the broader check.

Also drop the `is_llvm_coverage` batch-skip in `functional_tests.py` /
`integration_test_job.py` back to excluded, since coverage jobs are now
filtered out entirely at config time before any batch is scheduled - the
in-job per-batch skip is unreachable for them and only added maintenance
surface.

PRs touching production code are unaffected: `_has_build_digest_changes`
returns True for them, so the coverage family runs exactly as before -
degradation check, LBC cross-validation, and master's own baseline
publication are untouched.
scanhex12 pushed a commit to scanhex12/ClickHouse that referenced this pull request Jul 29, 2026
…merge job

`should_skip_job` already skipped the `LLVM_COVERAGE` merge job when a PR had
no build-digest-affecting changes, but the `amd_llvm_coverage` test-shard
batches and the coverage build still ran - burning CI time producing profdata
that the (already-skipped) merge job would never consume. ClickHouse#109668 made this
worse by also skipping only some batches within those jobs based on a
per-batch hash-bucket check, so a tests-only PR ended up with an inconsistent
mix of some batches running and others skipped.

Extend the existing `ci-no-coverage` label condition (which already skips the
build, all `amd_llvm_coverage` shards, `excluded_from_llvm` jobs, and the
merge job together) to also fire automatically whenever the PR has no
build-digest changes. This makes the skip consistent (the whole family or
none of it) and removes the now-dead single-test-type sub-job skip block and
the standalone merge-job-only skip, both superseded by the broader check.

Also drop the `is_llvm_coverage` batch-skip in `functional_tests.py` /
`integration_test_job.py` back to excluded, since coverage jobs are now
filtered out entirely at config time before any batch is scheduled - the
in-job per-batch skip is unreachable for them and only added maintenance
surface.

PRs touching production code are unaffected: `_has_build_digest_changes`
returns True for them, so the coverage family runs exactly as before -
degradation check, LBC cross-validation, and master's own baseline
publication are untouched.
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
clickhouse-test only treats files directly inside the suite root as test
cases for --run-by-hash-* bucketing (is_test_from_dir/get_selected_tests use
os.listdir, not recursive). A nested file like
tests/queries/0_stateless/helpers/httpclient.py or
tests/queries/0_stateless/data_avro/generate_avro.sh previously resolved to
a fabricated hash-batch identity based on its basename, letting a helper- or
fixture-only change skip most batches while real dependent tests went unrun.

Require the parent directory to be exactly the suite root before attempting
direct-hit or sibling-test resolution; otherwise return None so the caller
conservatively runs the batch.

Reported by review on ClickHouse#109668:
ClickHouse#109668 (comment)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…stead of just checking membership

Move the batch-skip check to after the is_sequential/is_parallel handling
so it operates on the modules this job invocation will actually run, not
the pre-flavor-filter set.

Most real integration test job configs run parallel_test_modules and
sequential_test_modules together in one invocation (no explicit
parallel/sequential option). For those, checking mere set membership only
let us skip the whole batch when neither side contained a changed module.
Now, when only one side contains a changed module, drop the other side
entirely (it would produce results identical to master) instead of running
it anyway - a real time saving even when the batch itself is not skipped.

Addresses review comment on ClickHouse#109668:
ClickHouse#109668 (comment)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…test-only-changes

Skip CI batches when only test files changed and none fall in the batch
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