Skip to content

Fix flaky test_parallel_quorum_actually_parallel - #103710

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix/test-quorum-inserts-parallel-timing-race
Apr 29, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix/test-quorum-inserts-parallel-timing-race

Conversation

@groeneai

@groeneai groeneai commented Apr 29, 2026 •

Copy link
Copy Markdown
Collaborator

The integration test test_parallel_quorum_actually_parallel is chronically flaky on sanitizer builds — 16 hits across 11 PRs in the last 30 days, including 2 master hits.

Root cause

The test starts a 5-second INSERT ... numbers(5) WHERE sleepEachRow(1) == 0 in a background pool, then issues 8 client/server operations on three replicas (2 quorum inserts + 6 SELECT COUNT() assertions) and expects COUNT() == 2 while the long insert is still running.

Under MSan, TSan, and ASan + UBSan builds those operations can take 10-20x longer than on a release build. When the cumulative time exceeds the 5-second window, the long insert has already committed by the time the test asserts COUNT() == 2, so it returns 7 instead:

File: test_quorum_inserts_parallel/test.py:61 - in test_parallel_quorum_actually_parallel
    assert node3.query(\"SELECT COUNT() FROM r\") == \"2\n\"
E   AssertionError: assert '7\n' == '2\n'

This pattern accounts for 10 of the 16 chronic failures recorded in CIDB over 30 days — including both master failures (amd_msan and amd_asan_ubsan, db disk, old analyzer).

Fix

Triple the per-row sleep (sleepEachRow(1) → sleepEachRow(3)) so the long insert runs for 15 seconds total. The test's assertions and parallel-quorum semantics are unchanged; the fix just gives a 3x safety margin against sanitizer-induced slowdowns.

Reproduction & verification

The race only manifests under heavy CI load, so I reproduced it locally by inserting time.sleep(1.5) between the operations to simulate sanitizer overhead:

  • Original sleepEachRow(1) + simulated slowdown → reliably fails with assert '7\n' == '2\n' (matching the CI failure exactly)
  • Fixed sleepEachRow(3) + simulated slowdown → passes
  • Fixed sleepEachRow(3) without slowdown → passes in 36s (no measurable runtime regression)

CI failure example: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100332&sha=&name_0=PR

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

Fix flaky test_parallel_quorum_actually_parallel integration test on sanitizer builds.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

cidb-session: cron:clickhouse-ci-task-worker:20260429-081500

Version info

  • Merged into: 26.5.1.180-master (included in 26.5 and later)
  • Backported to: 26.3.57.13

The test races: a 5-second `INSERT ... sleepEachRow(1)` runs in the
background while the test issues 8 client/server operations (2 quorum
inserts + 6 SELECT COUNT() assertions). Under sanitizer builds (`MSan`,
`TSan`, `ASan + UBSan`) those operations can take 10-20x longer than
on a release build, occasionally exceeding the 5-second window. When
that happens the long insert has already committed by the time the
test asserts `COUNT() == 2`, so it returns `7` instead and the test
fails:

    assert node3.query("SELECT COUNT() FROM r") == "2\n"
    AssertionError: assert '7\n' == '2\n'

This pattern accounts for 10 of the 16 chronic failures recorded in
CIDB over the last 30 days, including both master hits.

Triple the per-row sleep (1s -> 3s) so the long insert runs for 15s
total. The assertions still validate the same parallel-quorum
semantics; the test just gets a 3x safety margin against sanitizer
slowdowns. Locally reproduced the race deterministically by inserting
`time.sleep(1.5)` between operations, then confirmed the fix passes
with the same simulated slowdown.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100332&sha=&name_0=PR

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

a) Deterministic repro? Yes — reproduced locally by inserting time.sleep(1.5) between the operations in the test (simulates sanitizer slowdown). Failure: assert '7\n' == '2\n' at line 61, exactly matching the CI failure pattern. 1/1 reproduction.

b) Root cause explained? The test relies on a 5-second sleepEachRow(1) window staying open while 8 client/server operations execute. Under MSan/TSan/ASan + UBSan, those operations can take 10-20x longer than on a release build. When their cumulative wall-clock time exceeds 5 seconds, the long INSERT has already committed by the time the test asserts COUNT() == 2, so COUNT() returns 7 (5 long-insert rows + 2 short-insert rows).

c) Fix matches root cause? Tripling sleepEachRow(1) → sleepEachRow(3) extends the long-insert window from 5s to 15s, giving a 3x margin against sanitizer-induced slowdowns. This addresses the timing race directly, not a symptom.

d) Test intent preserved? Yes. The test still verifies parallel quorum inserts work concurrently with a long-running quorum insert. The semantics and assertions are unchanged — only the duration of the long insert is increased.

e) Both directions demonstrated?

  • sleepEachRow(1) + simulated slowdown → FAIL with '7\n' == '2\n'
  • sleepEachRow(3) + simulated slowdown → PASS
  • sleepEachRow(3) without slowdown → PASS (36s test runtime, no regression)

cidb-session: cron:clickhouse-ci-task-worker:20260429-081500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix — could you review this? It tripples the per-row sleep duration in the long parallel-quorum INSERT (1s → 3s) so that the long insert reliably stays alive long enough for the test's COUNT()==2 assertions on sanitizer builds. Test-only change, no behavior modification.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Apr 29, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f29ddc0]

Summary: ✅


AI Review

Summary

This PR makes test_parallel_quorum_actually_parallel more robust on sanitizer builds by extending the long insert duration from 5s to 15s and documenting the race mechanism; the change is narrowly scoped and appropriate for a CI-flakiness fix.

Missing context
  • ⚠️ No CI run results were attached to this review session, so runtime impact across full CI matrix could not be validated here.
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 Apr 29, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Apr 29, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 29, 2026
Merged via the queue into ClickHouse:master with commit e414630 Apr 29, 2026
165 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 29, 2026
@PedroTadim

Copy link
Copy Markdown
Member

Backporting to fix CI

@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 20, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 20, 2026
PedroTadim added a commit that referenced this pull request Oct 20, 2026
Backport #103710 to 26.3: Fix flaky test_parallel_quorum_actually_parallel
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 pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants