Skip to content

test(quic): expand quic_socket.cpp coverage#1071

Merged
kcenon merged 2 commits into
developfrom
test/issue-1065-quic-socket-coverage
Apr 27, 2026
Merged

test(quic): expand quic_socket.cpp coverage#1071
kcenon merged 2 commits into
developfrom
test/issue-1065-quic-socket-coverage

Conversation

@kcenon

@kcenon kcenon commented Apr 27, 2026

Copy link
Copy Markdown
Owner

What

Summary

Expands unit-test coverage of src/internal/quic_socket.cpp by adding 35 new tests targeting validation guards, public-API input variations, multi-instance state isolation, and struct/result edge cases.

Change Type

  • Test (new test cases)

Affected Components

  • tests/test_quic_socket.cpp (test additions only; no production code changed)

Why

Problem Solved

quic_socket.cpp was identified as the #4 worst-coverage target in the 2026-04-26 lcov re-measurement (43.7% line / 21.3% branch). This PR expands coverage of the surface reachable without an active QUIC peer.

Honest Scope Note

The acceptance criteria of #1065 (>= 80% line / >= 70% branch) cannot be fully met by these tests alone. The majority of quic_socket.cpp (handshake, frame processing, packet protection, retransmission) requires an in-process QUIC loopback fixture, which does not yet exist in this repo. This PR therefore uses Part of (not Closes).

The new tests still meaningfully exercise:

  • Role/state validation guards in connect() / accept() / close()
  • send_stream_data() and create_stream() / close_stream() early-return paths
  • Move-construction / move-assignment / self-move safety
  • Callback registration thread-safety surface
  • Enum value contracts and connection-id properties

Related Issues

Who

Reviewers

Required Approvals

  • Maintainer approval

When

Urgency

  • Normal

Target Release

Next minor (v2.x.x)

Where

Files Changed

File Type of Change
tests/test_quic_socket.cpp +583 lines (35 new tests)

API / Database Changes

None.

How

Implementation Details

Testing Done

  • Local toolchain (cmake/ninja/g++) not available — relying on CI
  • Tests follow established style of existing 25 tests in the file

Test Plan for Reviewers

  1. CI runs full suite on Ubuntu/macOS/Windows + sanitizers
  2. Verify coverage delta on src/internal/quic_socket.cpp (expect partial, not full, improvement)
  3. Confirm no production code changed

Breaking Changes

None.

Rollback Plan

Revert this commit; no schema or API changes.

Add 35 unit tests targeting public surface of quic_socket reachable
without an active QUIC peer:

- Construction / destruction lifetime (IPv6 socket, destructor with
  active receive, RFC 9000 connection ID length bounds)
- connect() validation guards: server-role rejection, empty/explicit
  server name, port-0 endpoint, post-close re-connect rejection
- accept() validation guards: client-role rejection, missing/empty
  cert paths, post-close re-accept rejection
- close() variations: non-zero error code, empty reason, long reason
  string, default arguments
- send_stream_data() validation: empty payload, oversized payload,
  fin flag, max stream id (all rejected when not connected)
- create_stream() / close_stream() validation guards
- Receive loop idempotency: stop without start, start twice,
  start-stop-start cycle
- State queries: state remains idle after failed connect,
  remote_endpoint defaults to zero, is_connected/is_handshake_complete
  consistency in idle state
- Multi-instance isolation: independent connection IDs,
  close on one instance does not affect another
- Move semantics: move-assignment transfers state,
  self-move-assignment is a no-op
- Callback edge cases: null callbacks accepted, overwrite replaces
- Enum sanity: quic_role and quic_connection_state numeric values
- const socket accessor

Acceptance criteria of #1065 (>= 80% line / >= 70% branch) cannot be
fully met without an in-process QUIC loopback fixture. These tests
expand coverage of reachable validation and state-machine paths only.

Part of #1065
Part of #953
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Metric Value
Line Coverage 66.5%
Branch Coverage 32.9%
Target 80% lines / 70% branches
Coverage Details

Full HTML report is available as a build artifact.

@kcenon kcenon merged commit d195280 into develop Apr 27, 2026
9 checks passed
@kcenon kcenon deleted the test/issue-1065-quic-socket-coverage branch April 27, 2026 22:46
kcenon added a commit that referenced this pull request Apr 28, 2026
…eer (#1079)

Add 8 new TEST_F cases under the existing QuicSocketHermeticTransportTest
fixture in tests/unit/quic_socket_branch_test.cpp. They use
make_loopback_udp_pair + mock_udp_peer to exercise paths that PR #1071
left uncovered because that PR only validated idle/disconnected state.

New paths driven:

- connect() success path past TLS init / derive_initial_secrets /
  start_handshake / queue_crypto_data / send_pending_packets /
  send_packet, with the loopback peer capturing the long-header
  Initial datagram and verifying the 0xC0+ first byte and a parsed
  src connection id.
- connect() state transition from idle to handshake_start/handshake.
- close() at the initial encryption level building a CONNECTION_CLOSE
  frame and dispatching it as a second datagram on the same socket.
- do_receive() lambda handing a real datagram to handle_packet, with
  the silent-drop branches taken when packet_parser::parse_header
  fails (1-byte input) or when get_read_keys reports keys-not-yet-
  derived (long-header Initial stub on a fresh client).
- stop_receive() correctness under an active peer-side sender.
- Distinct connection-id generation across two independent client
  sockets, asserted via SCID extraction from the captured Initial
  packets.
- connect() with an explicit non-empty SNI string still emitting a
  long-header Initial.

No new test_support files; no CMake changes (the file is already
linked to network::test_support at tests/CMakeLists.txt:4962).

The acceptance criteria of issue #1065 (>= 80% line / >= 70% branch
on src/internal/quic_socket.cpp) remain unreachable until Phase 2C
of #1074 lands mock_quic_peer_loop with TLS 1.3 key derivation, so
this PR ships incremental progress only.

Part of #1065
Part of #953
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.

2 participants