Skip to content

test(grpc): add 6 frame_injector-driven error TEST_F (Round 2 / Issue #1107)#1118

Merged
kcenon merged 1 commit intodevelopfrom
test/issue-1107-grpc-client-error-branch-coverage-round-2
May 9, 2026
Merged

test(grpc): add 6 frame_injector-driven error TEST_F (Round 2 / Issue #1107)#1118
kcenon merged 1 commit intodevelopfrom
test/issue-1107-grpc-client-error-branch-coverage-round-2

Conversation

@kcenon
Copy link
Copy Markdown
Owner

@kcenon kcenon commented May 9, 2026

Closes #1107

Summary

Round 2 of grpc/client.cpp coverage expansion using the Phase 2 substrate (frame_injector + mock_grpc_server_peer) merged in PR #1105. Round 1 sub-issues #994 / #1063 raised happy-path public-API coverage but client.cpp remained at 22.6% line / 9.5% branch in run 25430202846 because error branches require a peer that emits malformed/dropped/truncated/slow byte streams.

This PR is a direct gRPC analogue of the Round 2 http2 work landed in PR #1117 (Issue #1106).

Acceptance criteria mapping (#1107)

Criterion Coverage
connect timeout via drop on server SETTINGS DropFirstServerSettingsLeavesGrpcClientUnconnected
malformed SETTINGS-ACK via malform (flip type byte) MalformedServerSettingsAckTypeByteBlocksGrpcConnect
truncated response HEADERS via truncate TruncatedServerSettingsHeaderBlocksGrpcConnect and TruncateAtNineDropsResponsePayloadFailingCallRaw
non-OK gRPC-Status trailer dispatched NonOkGrpcStatusTrailerDispatchesGrpcErrorBranch
slow-write of DATA frame via slow_write SlowWriteServerFramesStillCompleteHandshake (gated outside coverage build)

New TEST_F cases

Test Branch driven
DropFirstServerSettingsLeavesGrpcClientUnconnected grpc_client::connect() connect-timeout when h2 SETTINGS never arrive
MalformedServerSettingsAckTypeByteBlocksGrpcConnect grpc_client::connect() returns error when h2 dispatch sees unknown frame type
TruncatedServerSettingsHeaderBlocksGrpcConnect grpc_client::connect() partial-read short-header path
NonOkGrpcStatusTrailerDispatchesGrpcErrorBranch call_raw grpc-status trailer scan + grpc_status != ok dispatch (lines 1264-1302 of client.cpp)
TruncateAtNineDropsResponsePayloadFailingCallRaw call_raw post-protocol-error / response-future-error branch when reply HEADERS+DATA+trailers all lose payload
SlowWriteServerFramesStillCompleteHandshake partial-read / accumulating-buffer branch in the underlying h2 frame-reader from inside grpc_client::connect() (gated outside NETWORK_COVERAGE_BUILD)

Substrate addition (tests/support only)

grpc_reply_mode::echo_unary_error_status — same HEADERS+DATA framing as echo_unary but the trailing HEADERS frame carries grpc-status: 14 (UNAVAILABLE) and grpc-message: peer-unavailable. Pure test-support extension; no production source files modified.

Test plan

cmake --build build --target network_grpc_client_branch_test -j 4
./build/bin/network_grpc_client_branch_test
# Expect: all TEST_F PASS

Out of scope

  • No src/ changes; test-only PR per issue scope.
  • gRPC frame parsing (frame.cpp already at 95.8%).
  • gRPC server (server.cpp already at 85.4%).
  • Service registry (service_registry.cpp already at 84.3%).

Notes

Local toolchain (cmake/g++) was unavailable in the work environment, so build verification is delegated to CI.

Round 2 of grpc/client.cpp coverage expansion using the Phase 2 substrate
(frame_injector + mock_grpc_server_peer) merged in PR #1105. Round 1
sub-issues #994/#1063 raised happy-path coverage but client.cpp remained
at 22.6% line / 9.5% branch on run 25430202846 because error branches
require malformed/dropped/truncated/slow byte streams.

New TEST_F cases (all gRPC analogues of #1106 http2_client patterns):

- DropFirstServerSettingsLeavesGrpcClientUnconnected
  injection_mode::drop on server SETTINGS strands the underlying h2
  handshake; grpc_client::is_connected() never flips true.

- MalformedServerSettingsAckTypeByteBlocksGrpcConnect
  injection_mode::malform with offset 3 / xor 0x0F flips frame type
  byte (0x04 -> 0x0B) so the client drops the unknown frame and
  cannot complete the SETTINGS exchange.

- TruncatedServerSettingsHeaderBlocksGrpcConnect
  injection_mode::truncate with truncate_at=4 leaves a partial
  9-byte HTTP/2 frame header on the wire, driving the partial-read
  branch in the underlying http2_client.

- NonOkGrpcStatusTrailerDispatchesGrpcErrorBranch
  new grpc_reply_mode::echo_unary_error_status emits the same
  HEADERS+DATA reply as echo_unary but the trailing HEADERS frame
  carries grpc-status: 14 (UNAVAILABLE) and a grpc-message entry,
  driving the grpc_status != ok dispatch in call_raw.

- TruncateAtNineDropsResponsePayloadFailingCallRaw
  injection_mode::truncate with truncate_at=9 is a no-op for the
  9-byte SETTINGS frames so the handshake completes, but the longer
  response HEADERS / DATA / trailers frames lose their payloads;
  call_raw resolves with an error.

- SlowWriteServerFramesStillCompleteHandshake (gated outside
  coverage build) drives the partial-read accumulator branch by
  pacing the server SETTINGS write byte-by-byte.

Substrate addition (tests/support only):
  grpc_reply_mode::echo_unary_error_status — emits trailers with
  grpc-status: 14 + grpc-message: peer-unavailable. Pure
  test-support extension; no production source files modified.

Acceptance: 5+ TEST_F cases covering the issue's required injection
modes (drop/malform/truncate/non-OK trailer/slow_write).

Part of #953
Closes #1107
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

Coverage Report

Metric Value
Line Coverage 69.7%
Branch Coverage 34.7%
Target 80% lines / 70% branches
Coverage Details

Full HTML report is available as a build artifact.

@kcenon kcenon merged commit c88f73a into develop May 9, 2026
9 checks passed
@kcenon kcenon deleted the test/issue-1107-grpc-client-error-branch-coverage-round-2 branch May 9, 2026 04:57
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