Skip to content

test: expand coverage for src/protocols/grpc/client.cpp #994

Description

@kcenon

Part of #953

What

Raise line coverage of src/protocols/grpc/client.cpp from 22.2% to >= 70%, and branch coverage from 8.7% to >= 60%.

Current state (2026-04-17 measurement, source PR #989):

  • Instrumented lines: 482 / ~1702 LOC
  • Lines hit: 107 / 482 (22.2%)
  • Branches: 81 / 926 (8.7%)
  • No dedicated unit test file found for this translation unit. Related tests exist only at the integration level (tests/test_grpc_integration.cpp, tests/test_grpc_client_server.cpp).

This is the largest file in the top-5 (~1702 LOC) and the only one without a unit test file. Coverage likely comes incidentally from integration tests.

Why

  • Lack of a unit test file means the gRPC client implementation has zero guard-rails for isolated-unit regressions. Integration tests catch end-to-end breakage but give poor signal on internal branches.
  • gRPC is an optional ecosystem integration (NETWORK_ENABLE_GRPC_OFFICIAL=OFF by default) but still shipped; untested branches will break downstream consumers that opt in.

Where

  • Source: src/protocols/grpc/client.cpp
  • New file to create: tests/unit/grpc_client_test.cpp
  • Existing integration tests (do not modify in this issue): tests/test_grpc_integration.cpp, tests/test_grpc_client_server.cpp, tests/test_grpc_service_registry.cpp

How

Approach

  1. Create tests/unit/grpc_client_test.cpp as the primary unit test file.
  2. Mock or stub transport layer so tests don't require a running server.
  3. Cover:
    • Channel setup (valid URI, invalid URI, TLS config variants)
    • Unary call lifecycle (success, deadline exceeded, cancelled, server returns error status)
    • Streaming-call state transitions (client-streaming, server-streaming, bidi)
    • Metadata handling (initial, trailing, custom keys)
    • Error status code mapping (all gRPC status codes)
  4. Wire up via the existing add_executable + gtest_discover_tests pattern used by other tests/unit/*.cpp.

Acceptance Criteria

  • tests/unit/grpc_client_test.cpp created and registered in CMake
  • src/protocols/grpc/client.cpp line coverage >= 70%
  • src/protocols/grpc/client.cpp branch coverage >= 60%
  • Unit tests run without requiring a live gRPC server
  • All tests pass on Ubuntu/macOS CI
  • ASAN/TSAN/UBSAN all green

Out of Scope

  • Enabling NETWORK_ENABLE_GRPC_OFFICIAL by default.
  • gRPC server-side coverage (separate follow-up).

Dependencies

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions