ClickhouseAlexey Bakharev and James CunninghamExplainer
How well is ClickHouse tested? A detailed view of increasing our own coverage
Summary
ClickHouse, with 2.6 million lines of C++ and over 80 daily pull requests, needed an automated way to assess test coverage. The team implemented Clang source-based coverage instrumentation, running 23 CI shards every three hours to produce a merged report. As of November 2026, the tests cover 91.8% of lines, 81.0% of branches, and 91.8% of functions. A differential coverage check on every PR compares the change against up to seven master baselines and gates merges if line coverage drops more than 0.3 percentage points. The team plans to pursue mutation testing and reduce the noise floor from background threads in future iterations.
Context
ClickHouse has about 2.6 million lines of C++ code and more than 80 pull requests land in master every day. The team needed an automated way to know which features, components, and settings are covered by tests, because manual tracking is impossible at that pace and scale.
Approach / What changed
ClickHouse measures test coverage using Clang’s source-based coverage instrumentation (-fprofile-instr-generate -fcoverage-mapping). CI runs 23 test shards (unit, functional, integration) in parallel on a binary built with -DWITH_COVERAGE=ON, merges the profiles into one tracefile, and renders an HTML report at coverage.clickhouse.com every 3 hours. Per-test coverage is collected via SYSTEM SET COVERAGE TEST and a per-test table. A differential coverage check on every PR compares the PR’s tracefile against up to seven master baselines and gates merges if total line coverage drops more than 0.3 percentage points below master.
Takeaways
ClickHouse achieves 91.8% line coverage, 81.0% branch coverage, and 91.8% function coverage using Clang source-based instrumentation across 23 CI shards.
A differential coverage check on every PR compares the change against up to seven master baselines and gates merges if total line coverage drops more than 0.3 percentage points below master.
Background threads and parallel execution create a noise floor of about 150 false ‘newly covered’ lines per run even with seven baselines; the team aims to reduce this to a single run.
FAQ
How does ClickHouse measure test coverage?
ClickHouse uses Clang's source-based coverage instrumentation (-fprofile-instr-generate -fcoverage-mapping). The binary is built with -DWITH_COVERAGE=ON, and CI runs 23 test shards in parallel. Each shard produces a .profraw file; llvm-profdata merges them into one .profdata, and llvm-cov produces the report.
How does the PR coverage gate work?
A differential coverage check runs on every PR. It compares the PR's tracefile against up to seven master baselines. If the total line coverage drops more than 0.3 percentage points below master, the PR fails the gate. The check also reports newly covered and lost baseline lines.
Why does coverage vary between runs?
Background threads and parallel execution cause a noise floor of a few hundred lines per run. With a single baseline, about 1,300 false 'newly covered' lines appear per run; using seven baselines reduces that to about 150. The team wants one run to be enough in the future.
Source and freshness
- Source
- clickhouse.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.