feat(tests/support): add HEADERS+DATA reply for h2 mock peer (Phase 2A.2)#1082
Merged
Merged
Conversation
Extend mock_h2_server_peer with an opt-in reply_mode parameter. The new echo_one mode reads one client request stream after the SETTINGS exchange (HEADERS plus any DATA frames up to END_STREAM) and replies on the same stream_id with a server HEADERS frame carrying ':status: 200' (HPACK static index 8 = 0x88) followed by a small END_STREAM DATA frame. The default drain_only mode is unchanged so existing Phase 2A timeout-path tests in http2_client_branch_test.cpp continue to drive the same code paths. Add a demo TEST_F that exercises http2_client::get against the new success path, asserting status_code == 200 and the response body. The test reaches handle_headers_frame and handle_data_frame branches that were previously only covered by the DISABLED_ConnectToHttpbin integration test the coverage workflow does not run. Update tests/support/README.md with a copy-paste usage example for reply_mode::echo_one and mark Phase 2A.2 as shipped in the Phase 2 progress table.
Contributor
Coverage Report
Coverage DetailsFull HTML report is available as a build artifact. |
This was referenced May 3, 2026
kcenon
added a commit
that referenced
this pull request
May 6, 2026
…#1104) Add friend-test injection so unit tests can drive two private server-side methods previously unreachable from public APIs: - messaging_quic_server::handle_packet (src/internal/experimental/quic_server.h:432) - messaging_ws_server::handle_new_connection (src/internal/http/websocket_server.h:415) Mechanism: new compile definition NETWORK_ENABLE_TEST_INJECTION gated behind BUILD_TESTS in cmake/network_system_targets.cmake. The two production headers gain a forward declaration block and a single 'friend class' line, all wrapped in '#if defined(NETWORK_ENABLE_TEST_INJECTION)'. When BUILD_TESTS=OFF the production binary is byte-identical to the previous develop tip. Probe types live entirely in tests/support/: - network_test_friends.h forward-declares the probes - quic_server_probe.{h,cpp} forwards to handle_packet - ws_server_probe.{h,cpp} forwards to handle_new_connection Demo tests verify end-to-end wiring: - QuicServerProbeTest.HandlePacket{Empty,Garbage}BufferDoesNotCrash - WsServerProbeTest.HandleNewConnectionEarlyReturnNoSessionManager - WsServerProbeTest.HandleNewConnectionEmptySocketEarlyReturn Per #1074 scope: no behavioral changes to src/. Phases 2A (#1075), 2A.2 (#1082), 2B (#1102), 2C (#1103) merged; 2E remains. Part of #1074
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
Phase 2A.2 of #1074. Extends
mock_h2_server_peerwith an opt-inreply_modeparameter so tests can exercise the http2_client response-success path against a hermetic loopback peer. The default mode (drain_only) is unchanged.Change Type
Affected Components
tests/support/mock_h2_server_peer.{h,cpp}-- newreply_mode::echo_onepathtests/unit/http2_client_branch_test.cpp-- new demo TEST_Ftests/support/README.md-- usage example + Phase 2 progress updateWhy
Problem Solved
http2_client::handle_headers_frameandhandle_data_framesuccess branches were only reachable via theDISABLED_ConnectToHttpbinintegration test that requires an external network. The Phase 2Amock_h2_server_peeronly performed the SETTINGS exchange and then drained client frames --http2_client::get()always timed out, so the post-SETTINGS success paths were unreachable from CI.Related Issues
http2_client.cppin test(http2): expand http2_client.cpp coverage to 80% line / 70% branch #1062Where
Files Changed
tests/support/mock_h2_server_peer.hreply_modeenum, constructor parameter, three new getterstests/support/mock_h2_server_peer.cpprun()reads one request stream and writes HEADERS+DATA replytests/unit/http2_client_branch_test.cppGetSucceedsWhenPeerRepliesWithHeadersAndDataTEST_Ftests/support/README.mdAPI Changes
mock_h2_server_peerconstructor gains a defaultedreply_mode mode = reply_mode::drain_onlyparameter (backward compatible -- all existing callers compile unchanged)request_received(),response_sent(),last_request_stream_id()How
Implementation Details
reply_modeenum with two values:drain_only(Phase 2A behavior, default) andecho_one(Phase 2A.2).run()checks the mode. Inecho_one::status: 200(HPACK indexed header field 0x88, RFC 7541 Appendix A static-table index 8) on the same stream_id."ok"and END_STREAM set.request_received_andresponse_sent_atomic flags.disconnect().Testing Done
src/internal/protocols/http2/frame.hmock_h2_server_peer peer(io())call retains the Phase 2A drain_only behavior via the default argumentTest Plan for Reviewers
Http2ClientHermeticTransportTest.GetSucceedsWhenPeerRepliesWithHeadersAndDatashould passhttp2_client_branch_test.cppandgrpc_client_branch_test.cppshould continue to pass unchangedBreaking Changes
None --
reply_modeparameter has a default value matching prior behavior.