Skip to content

Make test_parking_fires_on_idle_worker actually sleep - #127780

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-test-scheduler-cpu-parking-idle-sleeps
Oct 25, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-test-scheduler-cpu-parking-idle-sleeps

Conversation

@groeneai

@groeneai groeneai commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #117711

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):

...

Description

test_scheduler_cpu_parking/test.py::test_parking_fires_on_idle_worker failed with expected parks > 0, got 0 in Integration tests (arm_binary, 3/4) on #127761, whose wide_integer change does not touch the scheduler.

The test needs a serial sleepEachRow(0.5) phase in which the other pipeline workers have no task and park their CPU lease in the idle wait. The outer aggregate is count(), which reads no column, so the analyzer's RemoveUnusedProjectionColumnsPass removes both sleepEachRow projections: EXPLAIN shows only ReadFromSystemNumbers, and the query reads 90 numbers in about 4 ms. The test then passes only when a second worker happens to reach the idle wait before the query ends. In CIDB the test passed 5391 times in 30 days with a median of 437 ms, so the sleeps never ran in CI.

The change uses sum(s) over sleepEachRow(...) as s, so the sleeps are kept and the query gets the serial window the comment describes (about 7 s in total), and asserts SleepFunctionCalls == 90 before the parks asserts, so the test fails if the premise is optimized away again.

Validation on the master debug and ASan builds in the integration harness: with only the new assertion, the old query fails 3/3 with expected 90 sleep calls, got 0. With the change, 33 debug runs (four random-settings draws) and 10 ASan runs pass with 8 parks and 8 unparks each, a further 50 debug runs pass, and the whole module passes.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127780]

Version info

  • Merged into: 26.11.1.779-master (included in 26.11 and later)

The test needs a serial sleepEachRow(0.5) phase in which the other
pipeline workers have no task and park their CPU lease in the idle
wait. The outer aggregate was count(), which reads no column, so the
analyzer's RemoveUnusedProjectionColumnsPass removed both sleepEachRow
projections and the query read 90 numbers in a few milliseconds. The
test then passed only when a second worker happened to reach the idle
wait before the query ended, and failed with 0 parks otherwise
(Integration tests (arm_binary, 3/4) on PR ClickHouse#127761). CIDB: 5391 OK
runs in 30 days with a median test time of 437 ms, so the sleeps never
ran in CI.

Read the sleep column with sum(s) so the sleeps are kept (about 7 s,
the idle window the comment describes), and assert SleepFunctionCalls
== 90 before the parks asserts so the test fails if the premise is
ever optimized away again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings), plus my own review (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 The test now takes about 7 s instead of about 0.4 s AGREE, noted, not blocking That is the serial idle window the test was designed around; the sleeps are what make it independent of hardware and sanitizer speed.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-8:20261025-143700

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. With only the new SleepFunctionCalls == 90 assertion, the old query fails 3/3 in the integration harness (expected 90 sleep calls, got 0); EXPLAIN actions=1 of the old query shows no sleepEachRow.
b Root cause explained? count() reads no column, so RemoveUnusedProjectionColumnsPass drops both sleepEachRow projections; the query finishes in ~4 ms, there is no serial idle window, and parks happen only by chance (0 on the failing run).
c Fix matches root cause? Yes. sum(s) reads the sleep column, so the planned ~5 s serial window exists; no bound widened, no retry.
d Test intent preserved / new tests added? Yes. The test now exercises the idle-wait park it was written for (8 parks per run) and fails if its premise is optimized away.
e Both directions demonstrated? Old query + premise assertion: 3/3 FAIL. Fixed test: 33/33 debug and 10/10 ASan with 8 parks / 8 unparks each, 50/50 more debug runs, module 4/4.
f Fix is general across code paths? The file's other parking queries output sum(length(value)), so their reads are needed.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only fix; the query's settings are fixed; four random-settings draws covered).
h Backward compatible? (maintainer-approved exception only) N/A (test-only).
i Invariants and contracts preserved? parks == unparks asserted and held in every run; the module's other tests pass.

Session id: cron:clickhouse-impl-slot-5:20261025-140200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @serxa, could you review this and add the can be tested label so CI runs? Under count() the analyzer drops the unreferenced sleepEachRow projections, so IDLE_WORKER_QUERY never slept and parks happened only by chance; it now reads the sleep column via sum(s) and asserts SleepFunctionCalls == 90 first.

@clickhouse-gh

clickhouse-gh Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [41a612d]

Summary: ✅


AI Review

Summary

PR #127780 fixes the idle-worker parking test by consuming the sleepEachRow output through sum and asserting SleepFunctionCalls == 90 before checking parking. Reviewed commit 41a612d06db0e4b650fbb0338a836ac104b006c5, the full test module, relevant optimizer and scheduler paths, and all prior discussion. No actionable findings.

Missing context / blind spots
  • ⚠️ The integration harness was not rerun locally, and the current Praktika report exposes no per-test results. Runtime evidence relies on the author's reported three failures with the old query, 83 passing debug runs, 10 passing ASan runs, and a passing full module. Completed CI results would independently confirm this evidence.
Final Verdict

Status: ✅ Approve. No changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 25, 2026
@serxa serxa added the can be tested Allows running workflows for external contributors label Oct 25, 2026
@serxa serxa self-assigned this Oct 25, 2026
@serxa

serxa commented Oct 25, 2026

Copy link
Copy Markdown
Member

Seems good. Ping me when mergable

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 25, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@serxa it is mergeable from my side: CI on 41a612d finished green (Mergeable Check passed, including Integration tests (amd_asan_ubsan, flaky)). Only the private CH Inc sync is still pending.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 25, 2026
Merged via the queue into ClickHouse:master with commit ce88c15 Oct 25, 2026
352 of 353 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 25, 2026
@clickhouse-gh clickhouse-gh Bot added comp-scheduler Workload scheduler and resource management: CPU/IO/memory scheduling, concurrency control, worklo... and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-scheduler Workload scheduler and resource management: CPU/IO/memory scheduling, concurrency control, worklo... 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.

4 participants