Skip to content

test(core): expand coverage for unified_session_manager.cpp#1046

Merged
kcenon merged 1 commit into
developfrom
test/issue-1034-unified-session-manager-coverage
Apr 26, 2026
Merged

test(core): expand coverage for unified_session_manager.cpp#1046
kcenon merged 1 commit into
developfrom
test/issue-1034-unified-session-manager-coverage

Conversation

@kcenon

@kcenon kcenon commented Apr 26, 2026

Copy link
Copy Markdown
Owner

Closes #1034

What

Adds tests/unit/unified_session_manager_extra_coverage_test.cpp
a new gtest binary that targets branches and edge cases of
src/core/unified_session_manager.cpp not exercised by the existing
unified_session_manager_test.cpp.

Why

Issue #1034 (part of #953) requires raising line coverage of
src/core/unified_session_manager.cpp to >= 70% and branch coverage
to >= 60%. The pre-Step-1 baseline reported 26.1% line coverage (2026-04-13).
The uncovered region concentrates in error and boundary paths — exactly
the surfaces that regress during the ongoing Result<T> migration —
so this PR fills in those paths with hermetic unit tests.

Where

  • Source under test: src/core/unified_session_manager.cpp
  • New test file: tests/unit/unified_session_manager_extra_coverage_test.cpp
  • Build wiring: tests/CMakeLists.txt (registers
    network_unified_session_manager_extra_coverage_test via
    add_network_test)
  • Changelog: CHANGELOG.md and docs/CHANGELOG.md (Tests / Added)

How

New tests close the following previously-uncovered paths:

  • Default-constructed manager configuration defaults
  • is_backpressure_active() short-circuit when enable_backpressure is false
  • get_utilization() divide-by-zero guard when max_sessions == 0
  • add_session(session_handle, id) overload (pre-wrapped handle path,
    both explicit id and auto-generated id branches)
  • add_session_with_id rejection at the limit / explicit id passthrough /
    collision returning empty / auto-generated id prefix
  • Duplicate-id add_session does not inflate total_accepted
  • update_activity and remove_session returning false on missing ids
  • cleanup_idle_sessions no-op when nothing is idle (and on empty manager)
  • stop_all_sessions and clear_all_sessions equivalence and reusability
  • for_each over empty manager (mutable + const overloads)
  • generate_id uniqueness across threads (4 threads x 200 ids each)
  • set_max_sessions narrowing below current count blocks new accepts
    and toggles backpressure
  • Full stats population including idle_timeout and backpressure_active
  • Const get_session round-trip with type recovery
  • total_cleaned_up accumulation across multiple cleanup invocations

The source under test is not modified. No source refactoring or seam
insertion was needed — all branches are reachable through the public API.
Tests are hermetic: no network, no filesystem, only short sleep_for calls
(<= 50ms) for activity-driven cleanup paths, mirroring the existing
unified_session_manager_test.cpp style.

Test Plan

  • New file compiles with the rest of the test suite via gtest_main
  • No source changes to src/core/unified_session_manager.cpp
  • Conventional Commits format, English-only commits / PR / changelog
  • CI: Ubuntu / macOS / Windows multi-platform unit tests
  • CI: ASAN / TSAN / UBSAN sanitizer suites
  • CI: Coverage workflow confirms src/core/unified_session_manager.cpp
    reaches >= 70% line / >= 60% branch

Notes

  • Local C++ toolchain (cmake/ninja) is unavailable in this environment,
    so the build was not verified locally; CI is the source of truth here.
  • Test target name follows the existing convention used by
    network_tcp_socket_extra_coverage_test registered for test: expand coverage for src/tcp_socket.cpp #1032.
  • New test types (extra_tcp_session, extra_idle_session) live in an
    anonymous namespace inside the test TU and have local
    session_traits specializations to avoid collisions with the
    existing test_tcp_session / test_idle_session types in the
    sibling test binary.

Add tests/unit/unified_session_manager_extra_coverage_test.cpp covering
the previously uncovered branches of src/core/unified_session_manager.cpp:

- default-constructed manager configuration defaults
- is_backpressure_active() short-circuit when enable_backpressure is false
- get_utilization() divide-by-zero guard when max_sessions == 0
- add_session(session_handle, id) overload (pre-wrapped handle path)
- add_session_with_id rejection / explicit id / collision / auto-generated
- duplicate-id add_session not inflating total_accepted
- update_activity and remove_session returning false on missing ids
- cleanup_idle_sessions no-op when nothing is idle
- stop_all_sessions / clear_all_sessions equivalence and reusability
- for_each over empty manager (mutable + const)
- generate_id uniqueness across threads
- set_max_sessions narrowing below current count blocking accepts
- full stats population including idle_timeout / backpressure_active
- const get_session round-trip
- total_cleaned_up accumulation across multiple cleanup invocations

Register network_unified_session_manager_extra_coverage_test target in
tests/CMakeLists.txt and document the addition in both CHANGELOG.md
files.

Closes #1034
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Metric Value
Line Coverage 66.0%
Branch Coverage 32.6%
Target 80% lines / 70% branches
Coverage Details

Full HTML report is available as a build artifact.

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