test(mesh/session): cover get_session client-fallback + explicit-endpoint paths#601
Conversation
…oint paths get_session() lacked behavioral coverage for three branches that its _get_zenoh_session_directly sibling already pins: - auto-listener path where BOTH the listener open and the client-mode fallback raise (returns None, no cached session, two open() calls) - explicit-endpoint open success (ZENOH_CONNECT set: single direct open, session cached, refcount = 1) - explicit-endpoint open failure (ZENOH_LISTEN set: transport error returns None without a silent listener/client retry) Lifts strands_robots/mesh/session.py coverage 93% -> 97% (lines 628-651 were previously unexecuted). Tests mock zenoh so no broker or zenoh install is required.
yinsong1986
left a comment
There was a problem hiding this comment.
Summary
Test-only change (+66/-0 in tests/mesh/test_mesh_session.py) that closes the coverage gap on get_session()'s three untested behavioral tails (lines 628-651): listener+client both failing returns None with no cached session and refcount 0; explicit ZENOH_CONNECT opening directly and caching with refcount 1; and explicit ZENOH_LISTEN failing loudly (no silent listener/client downgrade). Tests mock zenoh (no broker or install required), assert on outputs/contract rather than internals (per AGENTS.md "Test behavior, not implementation"), and sit inside TestSessionLifecycle, whose autouse _reset_session fixture restores _SESSION/_SESSION_REFS before and after each test so there is no module-global state leak.
What's good
- Scope-disciplined: no production behavior altered; matches the PR title.
- Env mutation goes through
patch.dict("os.environ", ...)rather than raw assignment, so teardown is atomic (AGENTS.md PR #86 testing patterns). - Each new test pins a distinct contract branch with a clear docstring; the loud-on-misconfig assertion (
open.assert_called_once()for explicit endpoints) is the right behavioral pin. - No host paths, no non-ASCII in the diff.
Verification suggestions
python -m pytest tests/mesh/test_mesh_session.py -k TestSessionLifecycle -q (8 passed locally).
Problem
strands_robots/mesh/session.py::get_session()had three behavioral branches with no test coverage (lines 628-651, the explicit-endpoint and client-fallback-failure tails). Its sibling_get_zenoh_session_directlyalready pins the equivalent paths, so the public entry point was the gap. Module coverage sat at 93%.Change
Adds three behavioral tests to
TestSessionLifecycle(zenoh mocked, no broker or install required), asserting outputs/contract rather than internals:get_session()returnsNone, caches no session, refcount stays 0, and exactly twoopen()calls are made.ZENOH_CONNECTset): a single directopen(), session cached, refcount = 1, no listener/client dance.ZENOH_LISTENset): a transport error on the single explicit open returnsNonewith no silent listener/client retry (loud-on-misconfig contract).Result
strands_robots/mesh/session.pycoverage 93% -> 97% (lines 628-651 now executed). Verified the lines were unexecuted before this change by running the mesh suite against pre-change code. Test-only change; no production behavior altered.