Skip to content

test(tcp): expand coverage for tcp_socket.cpp#1045

Merged
kcenon merged 1 commit into
developfrom
test/issue-1032-tcp-socket-coverage
Apr 25, 2026
Merged

test(tcp): expand coverage for tcp_socket.cpp#1045
kcenon merged 1 commit into
developfrom
test/issue-1032-tcp-socket-coverage

Conversation

@kcenon

@kcenon kcenon commented Apr 25, 2026

Copy link
Copy Markdown
Owner

Closes #1032

What

Add tests/unit/tcp_socket_extra_coverage_test.cpp plus CHANGELOG entries
and a CMake registration. The new suite complements the existing
tcp_socket_test.cpp to push coverage for src/tcp_socket.cpp past the
>= 70% line / >= 60% branch bar set by Issue #1032.

Why

src/tcp_socket.cpp is one of the lowest-coverage files in the
network_system source tree per the #953 audit. The uncovered region
concentrates in error and boundary paths (rejection branches, idempotence,
post-close handler delivery, backpressure transitions) — exactly the surfaces
that regress most easily during the ongoing Result<T> migration. Bringing
this file over the 70/60 bar is a direct contribution to the #953 ecosystem-wide
coverage target.

Where

  • tests/unit/tcp_socket_extra_coverage_test.cpp (new, +540 lines)
  • tests/CMakeLists.txt (+5 lines, registers network_tcp_socket_extra_coverage_test)
  • CHANGELOG.md (+1 line)
  • docs/CHANGELOG.md (+5 lines)

No source changes under src/tcp_socket.cpp — tests are hermetic and only
exercise the existing public/internal surface.

How

Tests use a dedicated asio::io_context running on a background thread
and a loopback acceptor on a kernel-assigned port (mirrors the existing
tcp_socket_test.cpp fixture). Each test connects a client/server
tcp_socket pair via make_connected_pair() and exercises one of the
following gap areas:

  • try_send rejection when max_pending_bytes would be exceeded
  • async_send and try_send on a closed socket (handler error path)
  • start_read idempotence (compare_exchange_strong false branch)
  • start_read after close (early no-op via posted lambda)
  • reset_metrics clearing every counter (incl. peak_pending_bytes,
    rejected_sends, backpressure_events)
  • Backpressure activation at high_water_mark / release at low_water_mark
  • config() accessor for both custom and default configurations
  • Multiple observers attached to the same socket all receive data
  • detach_observer for an observer that was never attached is a no-op
  • Null receive/view/error/backpressure callback setters do not crash on
    later invocation
  • stop_read before start_read is harmless and the socket remains usable
  • Freshly-constructed default-state invariants (is_closed, pending bytes,
    metrics)

Test Plan

Notes

  • Surgical change: tests only. No modification of src/tcp_socket.cpp,
    no refactor, no style normalization.
  • Follows the same *_extra_coverage_test.cpp naming and registration
    pattern established by test: expand coverage for src/protocols/http2/hpack.cpp #1031 (hpack_extra_coverage_test.cpp).
  • All commits, this PR title/body, and the planned issue comment are in
    English per project policy.

Add tests/unit/tcp_socket_extra_coverage_test.cpp closing remaining gaps
in src/tcp_socket.cpp. Targets line >= 70% / branch >= 60% per #1032
acceptance criteria.

Areas exercised:
- try_send rejection when max_pending_bytes would be exceeded
- async_send and try_send on a closed socket (handler error path)
- start_read idempotence (compare_exchange_strong false branch)
- start_read after close (no-op via posted lambda)
- reset_metrics clearing every counter to zero
- Backpressure activation at high watermark and release at low watermark
- config() accessor for custom and default configurations
- Multiple observers receiving the same event
- detach_observer for an observer that was never attached (no-op)
- Null receive/view/error/backpressure callback setters
- stop_read before start_read
- Default-state invariants on a freshly constructed socket

Tests are hermetic: loopback acceptor on a kernel-assigned port, no
sleeps beyond a few hundred milliseconds for completion-driven paths.

Closes #1032
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Metric Value
Line Coverage 66.0%
Branch Coverage 32.6%
Target 80% lines / 70% branches
Coverage Details

Full HTML report is available as a build artifact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant