How well is ClickHouse tested? A detailed view of increasing our own coverage
ClickHouse's ~2.6M-line C++ codebase reaches 91.8% line, 81.0% branch and 91.8% function coverage, measured with Clang source-based coverage across 23 CI shards every 3 hours and published at coverage.clickhouse.com. Basic blocks, edges and the two Clang instrumentation modes (SanitizerCoverage vs. source-based) are explained, along with the profraw → profdata → llvm-cov pipeline and the continuous-mode trick that keeps profiles from servers that tests kill on purpose. An AI agent in ClickGap finds stable zero-hit gaps and writes guarded, flakiness-checked tests, merging 16 PRs that cover about 5,600 new lines. Per-test line coverage stored in CIDB (about 36B rows) drives test selection, so expensive sanitizer jobs run only the tests that touch changed code.
Related posts
- ClickGap: Autonomous QA for ClickHouse
ClickHouse mediumAdept
ClickGap is an autonomous QA agent that reviews every pull request merged into ClickHouse, writes and runs tests against real builds, bisects regressions, and files issues and test-only PRs without human sign-off. In five months it filed about 500 issues and 200 coverage PRs, more than half of the issues already closed as completed. Candidate findings must survive an adversarial reviewer and ten gates, eight enforced as plain code, including executed reproducers, valid citations, existing-test searches, mutation kill-tests for coverage claims, and matching against past false positives. Reviews cost a couple of dollars each, smaller models handle recoverable subtasks, and every cost cut must pass a recall benchmark that replays previously confirmed bugs.
- Testing the Performance of ClickHouse
ClickHouse mediumAdept
ClickHouse catches performance regressions in CI by running the reference and patched servers side by side on the same machine and alternating about 3000 end-to-end test queries between them. This cancels out environmental systematic errors. A non-parametric bootstrap on the difference of median run times yields a noise threshold T, and a change is flagged only when it exceeds both T and 5%. Queries with T of 10% or more are marked unstable. Regressions are investigated with the built-in sampling profiler (system.trace_log), differential flamegraphs, ProfileEvents and hardware counters, while historical results stored in ClickHouse help locate when a change was introduced. Keeping false positives low matters more than producing a green check, and many test queries turned out to measure nothing meaningful.
- Decorating a Christmas Tree With the Help Of Flaky Tests
ClickHouse mediumAdept
ClickHouse treats flaky tests as bugs to investigate rather than noise to mute or retry, and deliberately makes tests flakier to surface hidden issues. Its practices include randomizing the environment on every run, running new tests 100 times before merge, using new tests as a fuzzing corpus, injecting random sleeps and core switches around mutex operations, and running in parallel on slow machines. Results of all test runs, nearly 1.8 billion records and 5–9 million runs per day, are stored in ClickHouse itself. A 561-day by 3772-test pass/fail pixel map of the stateless functional tests, rendered by JavaScript querying ClickHouse directly, forms a 'Christmas tree' where horizontal red lines mark flaky tests and vertical red lines mark days master was broken.
- Agentic coding at ClickHouse
ClickHouse mediumAdept
ClickHouse uses coding agents, mainly Claude Code with Opus 4.6 and Codex CLI as a fallback, for daily work on its large C++ codebase, which the author says became practical with Claude Opus 4.5 in November 2025. Productive scenarios include typing specified code, finishing stale PRs, boilerplate and infra configs, merge conflicts, porting code between codebases, small refactorings, fixing paper cuts and exploring unfamiliar code. One port, fixing ClickHouse dialect support in the Polyglot SQL translator, took 36 hours and about $500. For automated code review, an in-house bot driving Copilot CLI with custom instructions far outperformed GitHub's Copilot integration, leaving humans to judge architecture while the bot catches race conditions and resource bugs. The recommendation is to start with a CLI agent rather than an IDE-integrated one, always review generated diffs, and motivate adoption by example rather than mandate.
- Trace similarity systems on top of ClickHouse to analyze crash stack traces from our CI
ClickHouse mediumAdept
ClickHouse built a crash-deduplication pipeline for its CI that groups similar stack traces from fuzzing, stress and functional tests using the TraceSim similarity method, implemented almost entirely in ClickHouse SQL. Crash logs are pulled from a CI logs cluster into a separate analysis cluster every 30 minutes via a refreshable materialized view. SQL UDFs strip addresses, file/line info, ABI tags and LLVM suffixes from frames on the fly so cleaning logic can change without reprocessing. Identical cleaned traces are hashed and matched against known GitHub issues, insignificant traces are filtered by PR count and master presence, and the rest are compared with weighted arraySimilarity to open or update issues.