test(tcp): expand coverage for tcp_socket.cpp#1045
Merged
Conversation
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
Contributor
Coverage Report
Coverage DetailsFull HTML report is available as a build artifact. |
This was referenced Apr 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1032
What
Add
tests/unit/tcp_socket_extra_coverage_test.cppplus CHANGELOG entriesand a CMake registration. The new suite complements the existing
tcp_socket_test.cppto push coverage forsrc/tcp_socket.cpppast the>= 70% line / >= 60% branchbar set by Issue #1032.Why
src/tcp_socket.cppis one of the lowest-coverage files in thenetwork_systemsource tree per the #953 audit. The uncovered regionconcentrates 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. Bringingthis 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, registersnetwork_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 onlyexercise the existing public/internal surface.
How
Tests use a dedicated
asio::io_contextrunning on a background threadand a loopback acceptor on a kernel-assigned port (mirrors the existing
tcp_socket_test.cppfixture). Each test connects a client/servertcp_socketpair viamake_connected_pair()and exercises one of thefollowing gap areas:
try_sendrejection whenmax_pending_byteswould be exceededasync_sendandtry_sendon a closed socket (handler error path)start_readidempotence (compare_exchange_strong false branch)start_readafterclose(early no-op via posted lambda)reset_metricsclearing every counter (incl.peak_pending_bytes,rejected_sends,backpressure_events)high_water_mark/ release atlow_water_markconfig()accessor for both custom and default configurationsdetach_observerfor an observer that was never attached is a no-oplater invocation
stop_readbeforestart_readis harmless and the socket remains usableis_closed, pending bytes,metrics)
Test Plan
cmake/ninja),so build and test verification is delegated to CI on this PR.
Analysis workflow in line with Expand unit test coverage from 40% to 80% #953 / test: expand coverage for src/tcp_socket.cpp #1032 acceptance criteria.
Notes
src/tcp_socket.cpp,no refactor, no style normalization.
*_extra_coverage_test.cppnaming and registrationpattern established by test: expand coverage for src/protocols/http2/hpack.cpp #1031 (
hpack_extra_coverage_test.cpp).English per project policy.