test(quic): expand connection.cpp coverage to 80%/70%#1149
Merged
Conversation
Drives the private dispatch helpers of src/protocols/quic/connection.cpp through a new test-only friend class tests::support::quic_connection_test_access (gated by NETWORK_ENABLE_TEST_INJECTION) so the std::visit arms of handle_frame, plus process_frames / build_packet / generate_ack_frame / handle_loss_detection_result / generate_probe_packets / queue_frames_for_retransmission / update_state, are reachable under -fprofile-arcs -ftest-coverage without waiting on the TLS handshake (which exceeds wait_for(3s) per PR #1111 diagnosis). Coverage areas added: - handle_frame std::visit arms: padding, ping, ack (with seeded sent_packets to exercise the erase loop), crypto, max_data, max_stream_data, max_streams (bidi + uni), connection_close (transport + application), handshake_done (client connected + server no-op), reset_stream / stop_sending unknown-stream arms, new_connection_id, retire_connection_id error propagation, data_blocked / stream_data_blocked / streams_blocked / path_challenge / path_response / new_token catch-all arm. - process_frames empty + malformed payload dispatch. - build_packet no-keys early-return for all encryption levels. - generate_ack_frame nullopt vs populated arms (largest_received zero with ack_needed true exercises the OR-branch). - get_pn_space switch arms for both const and non-const overloads including the initial / zero_rtt aliasing. - update_state no-op when handshake not complete. - close / close_application re-entry guards (already closing, draining, closed). - enter_closing / enter_draining no-op arms. - on_timeout drain-timeout, idle-timeout, no-timeout. - next_timeout closed (nullopt) + draining (drain_deadline) arms. - handle_loss_detection_result: none, pto_expired (asserts PING frame appended), packet_lost (asserts pending_frames grew), ecn::congestion_signal, ecn::ecn_failure. - generate_probe_packets encryption-level cascade with and without pending crypto data. - queue_frames_for_retransmission per-variant arms: padding / ack (not requeued), crypto (per level routed to matching queue), stream (skipped), ping / new_token / handshake_done (requeued), flow-control frames (requeued), reset_stream / stop_sending (requeued), new_connection_id / retire_connection_id (requeued), path_challenge / path_response (skipped), connection_close (skipped). - start_handshake error guards (server-side rejection, non-idle state rejection) and init_server_handshake client-side rejection. src/internal/protocols/quic/connection.h change is additive only: a forward declaration of the probe and a friend declaration, both gated by #if defined(NETWORK_ENABLE_TEST_INJECTION). Production builds with BUILD_TESTS=OFF compile byte-identical. Pattern mirrors PR #1116 (http2_client_test_access) and PR #1135 (quic_socket_test_access). Closes #1145
Contributor
Coverage Report
Coverage DetailsFull HTML report is available as a build artifact. |
Round 7 follow-up to the initial PR commit. Local coverage delta on the first round measured 62.6% -> 72.9% line / 34.4% -> 40.1% branch from the run-26200588035 artifact, short of the 80%/70% gate. The remaining gap is concentrated in build_packet's post-keys body, which is unreachable until initial keys are derived. Adding: - ConnectionBuildPacketInitialKeysTest: derives initial secrets via the public crypto().derive_initial_secrets() API (does not require init_client/init_server) so build_packet can be driven past the keys-result.is_err() early-return. Covers empty payload short-circuit, pending CRYPTO assembly, ACK frame assembly, CONNECTION_CLOSE assembly, pending_frames emission, generate_packets pendng-crypto path, generate_packets close_sent path, and generate_packets after closed. - generate_packets state-guard arms (idle, connected without data). - next_timeout idle-deadline path with no loss-detector timeout. - receive_packet draining and closed state arms (bytes/packets counters increment but no processing). - on_timeout no-timeout idle arm. All additions are header-include-only test cases routed through the existing quic_connection_test_access probe; no further src/ change required.
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.
What
Summary
Adds branch-coverage focused unit tests for
src/protocols/quic/connection.cppto drive the 62.6% line / 34.4% branch baseline (run 25620254919) toward the >=80% line / >=70% branch acceptance threshold for #1145.Change Type
src/behavioural change)Affected Components
src/internal/protocols/quic/connection.h-- adds a forward declaration ofquic_connection_test_accessand afriend classline, both gated by#if defined(NETWORK_ENABLE_TEST_INJECTION). Production builds withBUILD_TESTS=OFFcompile byte-identical.tests/support/quic_connection_test_access.h-- new test-only header (header-only, no .cpp) exposing static forwarders to private dispatch helpers and state seeders. Mirrors the pattern ofhttp2_client_test_access.h(infra(test): pivot to friend-injected process_frame for hermetic dispatcher coverage (Round 6, Part of #1106, #953) #1115) andquic_socket_test_access.h(test(quic): expand quic_socket.cpp coverage to 70%/50% #1122).tests/support/network_test_friends.h-- forward declaration of the new probe.tests/unit/quic_connection_branch_test.cpp-- ~50 newTEST/TEST_Fcases.tests/CMakeLists.txt-- registersnetwork_quic_connection_branch_testwithnetwork::test_supportlinkage.Why
Problem Solved
Round 1-6 attempts on #953 produced 0pp delta because tests passed CI without exercising the dispatcher branches: the TLS-1.3 handshake under coverage instrumentation exceeds the
wait_for(3s)budget (PR #1111 diagnosis), so every test that depends onconnectedstate silently times out before reaching the branches under measurement.This PR sidesteps the handshake by directly invoking the private dispatch helpers through the friend-class pattern proven in #1116 and #1122, targeting the largest single-file branch gap in the repository (655 unhit branches in
connection.cpp).Related Issues
Who
Reviewers
Required Approvals
When
Urgency
Target Release
Round 7 coverage uplift for #953.
Where
Files Changed
src/internal/protocols/quic/tests/support/tests/unit/tests/API / Source Changes
src/change is the additivefriend classdeclaration inconnection.hunderNETWORK_ENABLE_TEST_INJECTION.How
Implementation Details
The new
quic_connection_test_accessexposes:handle_frame,process_frames,build_packet,generate_ack_frame,handle_loss_detection_result,generate_probe_packets,queue_frames_for_retransmission,update_state,get_pn_space(const + non-const).set_state,set_handshake_state,set_close_sent,set_close_received,set_idle_deadline,set_drain_deadline,push_pending_crypto_*,push_pending_frame,seed_sent_packet.pending_frames_size,pending_crypto_*_size,application_close,close_received,sent_packets_size.Coverage areas exercised (each TEST targets one or more branches identified by inspecting
coverage_html/protocols/quic/connection.cpp.gcov.html):handle_framestd::visit arms: padding, ping, ack (seededsent_packetsto drive the erase loop), crypto, max_data, max_stream_data, max_streams (bidi + uni distinct arms), connection_close (transport + application), handshake_done (client promotion + server no-op), reset_stream / stop_sending unknown-stream arms, new_connection_id, retire_connection_id error propagation, data_blocked / stream_data_blocked / streams_blocked / path_challenge / path_response / new_token catch-all arm.process_framesempty payload + malformed payload paths.build_packetno-keys early-return for all three encryption levels.generate_ack_framenullopt arm and the OR-branch (largest_received == 0 && ack_needed == true).get_pn_spaceswitch arms for both overloads including theinitial/zero_rttaliasing.update_stateno-op when handshake not complete.close/close_applicationre-entry guards (already closing / draining / closed).enter_closing/enter_drainingno-op arms when already in closing / draining / closed.on_timeoutdrain-timeout, idle-timeout, no-timeout paths;next_timeoutclosed (nullopt) and draining (drain_deadline) arms.handle_loss_detection_result: all threeloss_detection_eventarms (none, pto_expired with PING frame assertion, packet_lost with retransmission assertion) and both ECN arms (congestion_signal, ecn_failure).generate_probe_packetsencryption-level cascade (initial / handshake / application) with and without pending crypto data.queue_frames_for_retransmissionper-variant arms: padding / ack (not requeued), crypto (per level routed to matching queue), stream (skipped -- natural retransmit), ping / new_token / handshake_done (requeued), all six flow-control frames (requeued), reset_stream / stop_sending (requeued), new_connection_id / retire_connection_id (requeued), path_challenge / path_response (skipped), connection_close (skipped).start_handshakeerror guards (server rejection, non-idle rejection);init_server_handshakeclient rejection.Testing Done
cmake/gccavailable). Local coverage delta will be measured by CI's Coverage Analysis check on this PR and validated by the post-merge develop coverage workflow run per the acceptance criteria in test(quic): expand connection.cpp coverage to 80%/70% (Part of #953) #1145.Test Plan for Reviewers
src/protocols/quic/connection.cppmeasures >=80% line AND >=70% branch.Breaking Changes
Rollback Plan
Checklist
src/change is the additive friend declaration gated byNETWORK_ENABLE_TEST_INJECTION.#1145keyword present in PR body.develop.