Skip to content

Fix flaky test_rabbitmq_csv_with_delimiter - #108253

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test_rabbitmq_csv_with_delimiter
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test_rabbitmq_csv_with_delimiter

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

No related open issue found.

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

Fix the flaky integration test test_storage_rabbitmq/test.py::test_rabbitmq_csv_with_delimiter.

The test publishes 50 CSV messages and polls SELECT * FROM rabbitmq against a fixed DEFAULT_TIMEOUT_SEC (60s) wall-clock deadline that is never extended. On a contended sanitizer runner the 50 rows can take longer than 60s to fully arrive, so the loop hits its deadline mid-consumption and calls pytest.fail, even though it is still steadily consuming and would have passed shortly after. The CI run that prompted this fix reran the single test in isolation and it passed in 65.27s, just past the 60s budget.

CIDB shows 14 such timeouts (test.py:312) in 30 days across 11 unrelated PRs and 3 master runs, spanning amd_asan_ubsan, amd_msan, arm_binary and amd_llvm_coverage builds. A recent example: Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6), https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=2a3a502d2ed&name_0=MasterCI&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%206%2F6%29

Fix: reset the no-progress deadline to now + DEFAULT_TIMEOUT_SEC whenever the accumulated result grows, so the loop waits as long as rows keep arriving and fails only after a genuine DEFAULT_TIMEOUT_SEC-long stall. This mirrors the progress-based deadline already used by check_expected_result_polling for the same class of flakiness, and preserves the test's ability to detect a stalled consumer.

Validation (timing flake, so the failing direction is shown via a virtual-clock simulation of a slow runner): old loop FAILs at ~60s, new loop passes at 65s/120s, and a never-delivering consumer still FAILs at ~60s (genuine-stall detection intact). The real integration test passes locally (1 passed in 137.27s).

…ption progresses

The test publishes 50 CSV messages and then polls
`SELECT * FROM rabbitmq` against a fixed `DEFAULT_TIMEOUT_SEC` (60s)
wall-clock deadline that is never extended. On a contended sanitizer
runner the 50 rows can take longer than 60s to fully arrive, so the
loop hits its deadline mid-consumption and calls `pytest.fail`, even
though the test is still steadily consuming and would have passed
shortly after. CI confirms this: the failing 6/6 ASan batch run reran
the single test in isolation and it passed in 65.27s, just past the 60s
budget. CIDB shows 14 such timeouts (test.py:312) in 30 days across 11
unrelated PRs and 3 master runs, spanning amd_asan_ubsan, amd_msan,
arm_binary and amd_llvm_coverage builds.

Fix: reset the no-progress deadline to `now + DEFAULT_TIMEOUT_SEC`
whenever the accumulated result grows, so the loop waits as long as
rows keep arriving and fails only after a genuine
`DEFAULT_TIMEOUT_SEC`-long stall. This mirrors the progress-based
deadline already used by `check_expected_result_polling` for the same
class of flakiness (see "Fix flaky test_rabbitmq_big_message"), and
preserves the test's ability to detect a stalled consumer.

A virtual-clock simulation of a slow runner reproduces the failure with
the old loop (FAIL at ~60s) and passes with the new loop (at 65s/120s),
while a never-delivering consumer still fails at ~60s. The real
integration test passes locally (1 passed in 137.27s).

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? This is a timing flake (60s wall-clock poll budget vs slow-but-progressing consumption on contended sanitizer runners), so it does not reproduce on demand on a healthy local runner. It is reproduced deterministically by a virtual-clock simulation of the poll loop: modeling the 50-row set arriving at ~65s (matching the observed isolated-retry pass at 65.27s) makes the OLD loop FAIL at ~60s every time.
b Root cause explained? The loop sets deadline = now + 60s once and never extends it. Each poll iteration costs query latency (inflated under ASan/MSan) + sleep(0.05). When full delivery of the 50 messages takes longer than 60s of wall clock, the loop reaches its fixed deadline while still mid-consumption and calls pytest.fail, despite the result still growing every iteration.
c Fix matches root cause? Yes. The fix resets the no-progress deadline to now + DEFAULT_TIMEOUT_SEC whenever the accumulated result grows, so the budget measures time-since-last-progress rather than total wall clock. This directly targets the mechanism in (b). It is the same progress-based deadline already used by the sibling helper check_expected_result_polling.
d Test intent preserved / new tests added? Preserved. The final rabbitmq_check_result(result, True) assertion is unchanged, so the test still verifies CSV-with-delimiter ingestion correctness (keys/values 0..49). The fix only changes WHEN the loop gives up: it still fails after a genuine 60s stall (no infinite wait), so it retains its ability to catch a stalled/broken consumer. No new test needed (this is a flaky-test timing fix, not a code bug).
e Both directions demonstrated? Yes. Simulation: OLD loop FAILs at ~60s on a slow runner; NEW loop PASSes at 65s/120s while consuming; a never-delivering consumer still FAILs at ~60s. Real run: the integration test passes with the fix (1 passed in 137.27s, job Ok, Failures: 0/1).
f Fix is general, not a narrow patch? Scoped deliberately. Three sibling tests share this inline-poll idiom (json/macros/tsv), but CIDB shows their recent failures are at cluster.start()/wait_rabbitmq_to_start() (broker-startup infra), a different root cause — not the poll-loop timeout. Only test_rabbitmq_csv_with_delimiter fails at the poll loop (test.py:312, all 14/14 hits), so only it is changed here to avoid speculative edits to tests failing for unrelated reasons. The shared helper check_expected_result_polling already carries this same progress-reset logic.

Session id: cron:clickhouse-worker-slot-0:20260623-025300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov — review per your request on #108014. Test-only fix: the CSV poll loop now resets its no-progress deadline while rows keep arriving, so a slow-but-progressing consumer on a contended sanitizer runner is no longer abandoned at the fixed 60s budget; the final correctness assertion is unchanged.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c339789]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, old analyzer, 4/6) ERROR
Timeout FAIL cidb
Integration tests (amd_msan, 4/6) ERROR
Timeout FAIL cidb

AI Review

Summary

This PR changes test_rabbitmq_csv_with_delimiter so its polling deadline is reset while the accumulated RabbitMQ result grows, matching the progress-based timeout pattern already used by check_expected_result_polling. I did not find any correctness or CI-reliability issue that warrants an inline finding.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.50% 92.50% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 353 line(s), 25 function(s) across 128 file(s) · Details

Top files
  • src/Storages/WindowView/StorageWindowView.cpp: 22 line(s), 1 function(s)
  • src/Storages/ObjectStorageQueue/ObjectStorageQueueIFileMetadata.cpp: 12 line(s), 1 function(s)
  • src/Storages/MergeTree/ReplicatedMergeTreeRestartingThread.cpp: 12 line(s)
  • src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesGroupArray.h: 10 line(s), 8 function(s)
  • src/Dictionaries/RegExpTreeDictionary.h: 9 line(s), 7 function(s)

Full report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI fully finished on c33978909a0 (Finish Workflow SUCCESS 10:54:33Z, 0 pending). The fix target test_storage_rabbitmq/test.py::test_rabbitmq_csv_with_delimiter PASSED on every shard that ran it (amd_asan_ubsan 6/6, amd_msan 6/6, amd_tsan 6/6, arm_binary distributed-plan 2/4, amd_llvm_coverage 5/5, asan flaky).

Two reds remain, both NOT caused by this change:

  • Integration tests (amd_asan_ubsan, db disk, old analyzer, 4/6) and Integration tests (amd_msan, 4/6) -- job-level session-timeout occurred during test execution (the whole 4/6 batch hit the 2h wall clock). This is a chronic batch-timeout on the heavy 4/6 integration shard, seen across 14+ unrelated PRs in the last 30 days; it is unrelated to the RabbitMQ CSV poll-deadline fix in this PR. Mergeable Check / PR reflect those two batch timeouts.

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

@groeneai

Copy link
Copy Markdown
Collaborator Author

Superseded by #108364 (merged 2026-06-24), which fixes the same test_rabbitmq_csv_with_delimiter timeout flakiness more comprehensively.

That PR factors the inline direct-select poll loop into a shared poll_direct_select_result helper that resets the polling deadline whenever consumption makes progress, and applies it to all direct-select RabbitMQ tests (test_rabbitmq_select, json_without_delimiter, csv_with_delimiter, macros) rather than just csv_with_delimiter. It is a strict superset of this PR's single-test inline patch, so I am closing this as redundant.

The flaky test is now fixed on master. Thanks @pamarcos.

@groeneai groeneai closed this Jun 24, 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 pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants