Skip to content

Expand unit test coverage from 40% to 80% #953

@kcenon

Description

@kcenon

What

Drive network_system line coverage from 65.1% to 80% and branch coverage from 31.1% to 70% (measured on develop, 2026-04-20, coverage run 24659295053). The remaining gap is concentrated in protocol implementation files whose existing tests cover happy paths but not error/boundary branches.

History note (2026-04-16): This epic originally targeted ~40% coverage with 60+ untested modules. That premise was stale — sub-issues #982, #983, #984, #985 were closed after auditing the existing tests/unit/ tree (~112 test files, ~44,200 LOC, ~2,989 GTEST cases). The real gap is that many existing tests do not exercise error paths, branch combinations, and edge cases in the protocol code.

Progress note (2026-04-22): Step 1 (coverage measurement fix) is complete via #986, #987, #989. Step 2 (narrow test expansion) is in progress with #991, #992, #993, #990, #994 closed.

Why

  • 80% line coverage is the explicit v1.0 target for this project (see Prepare network_system for v1.0 release #964 dependency)
  • Ecosystem peers (database_system: 87%, thread_system: 72%) are above network_system
  • Result<T> migration and API stabilization increase regression risk on low-coverage protocol code
  • Branch coverage at 31.1% means ~25,000 branches go untested — many are error paths whose failure modes are not verified

Where

Current baseline (post Step 1)

Metric Value Target Gap
Line coverage 65.1% (15045 / 23099) 80% ~3,434 lines
Branch coverage 31.1% (11370 / 36532) 70% ~14,202 branches

Coverage workflow configuration (verified current)

.github/workflows/coverage.yml now builds with:

-DBUILD_WITH_COMMON_SYSTEM=ON
-DBUILD_WITH_LOGGER_SYSTEM=ON
-DBUILD_WITH_THREAD_SYSTEM=ON
-DBUILD_WITH_CONTAINER_SYSTEM=ON
-DBUILD_MESSAGING_BRIDGE=ON

Branch coverage is captured via lcov --rc lcov_branch_coverage=1 and rendered with genhtml --branch-coverage.

Worst-coverage implementation files (pre-Step-1 snapshot, needs re-measurement)

These file-level numbers were collected from the 2026-04-13 run before the BUILD_WITH_* flags were enabled. Re-measurement with the current workflow is pending. Already-addressed files are marked.

  • protocols/quic/frame.cpp — 15.0% of 600 lines (file is now 1203 lines; existing tests cover build/parse happy paths only)
  • internal/http_parser.cpp — 6.0% of 348 lines
  • tracing/exporters.cpp — 7.4% of 340 lines
  • protocols/quic/crypto.cpp — 12.1% of 313 lines (addressed by test: expand coverage for src/protocols/quic/crypto.cpp #993 / PR test(quic): add extended coverage tests for crypto module #1002)
  • protocols/http2/frame.cpp — 12.9% of 310 lines
  • protocols/quic/transport_params.cpp — 4.2% of 289 lines
  • protocols/http2/hpack.cpp — 13.5% of 244 lines
  • core/unified_session_manager.cpp — 26.1% of 222 lines
  • protocols/quic/packet.cpp — 11.0% of 210 lines
  • protocols/quic/loss_detector.cpp — 7.6% of 210 lines
  • tcp_socket.cpp — 14.8% of 209 lines
  • internal/utils/compression_pipeline.cpp — 12.5% of 200 lines
  • internal/http_error.cpp — 3.2% of 190 lines

How

Step 1 — Fix the measurement (DONE)

Step 2 — Narrowly-scoped test issues (IN PROGRESS)

For each remaining file still under 70% with >100 lines, open a single-file test expansion issue (size/S or size/M). Do not open XL epics.

Closed sub-issues (folded test expansion):

Open / upcoming sub-issues: see issues labeled Part of #953.

Step 3 — Close this epic when the acceptance criteria below are met

Acceptance Criteria

  • Coverage workflow rebuilt with all BUILD_WITH_* options enabled
  • Branch coverage captured (not "no data found")
  • Re-measured line coverage recorded on this issue (65.1% as of 2026-04-20)
  • Overall line coverage >= 80% (codecov)
  • Branch coverage >= 70%
  • All narrow test-expansion follow-ups are closed
  • All tests pass on Ubuntu/macOS/Windows CI
  • All sanitizer builds (ASAN, TSAN, UBSAN) pass

Dependencies


Update (2026-04-26)

Re-measurement on develop @ 05c1b7b

Coverage workflow run 24947193873:

Metric Baseline 2026-04-20 Current 2026-04-26 Target Gap
Line coverage 65.10% (15,045 / 23,099) 66.59% (15,382 / 23,099) 80% -13.41%p
Branch coverage 31.13% (11,370 / 36,532) 32.95% (12,039 / 36,532) 70% -37.05%p

The denominator is unchanged — sub-issues #1020-#1034 added tests but did not modify the source LOC pool. Net delta: line +337 hit / branch +669 hit.

Step 2 sub-issues closed in this batch (2026-04-24 to 2026-04-26)

#1020, #1021, #1022 (closed as not-planned), #1023, #1024, #1025, #1026, #1027, #1028, #1029, #1030, #1031, #1032, #1033, #1034 — all merged via PRs #1023-style follow-up to #1047.

Where section is now obsolete

The pre-Step-1 file list above (e.g. protocols/quic/frame.cpp 15.0%, protocols/http2/hpack.cpp 13.5%) has been fully addressed. New worst-coverage files identified from the 2026-04-26 measurement:

Priority File LOC Line% Branch% Note
1 protocols/http2/http2_client.cpp 576 18.8% 9.9% Follow-up to #991 (happy paths only)
2 protocols/grpc/client.cpp 482 22.6% 9.5% Follow-up to #994
3 protocols/http2/http2_server.cpp 554 38.3% 19.4% Follow-up to #992
4 internal/quic_socket.cpp 439 43.7% 21.3% New target
5 experimental/quic_server.cpp 378 43.7% 17.5% New target
6 http/websocket_server.cpp 308 39.9% 19.7% New target

Next steps (Step 2 continues)

  • Open narrow test-expansion sub-issues for the six files above (Part of #953).
  • Re-measure after each merge; expect ~80% line coverage to require ~3,000 additional hit lines.
  • Branch coverage target (70%) is the larger gap and may require explicit error-path tests beyond what unit tests typically cover — consider integration-level fuzzing if line target is reached but branch is not.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions