Skip to content

test: split unit_tests.cpp with TCP messaging fixture#1092

Merged
kcenon merged 1 commit into
developfrom
feat/issue-1088-split-unit-tests
May 1, 2026
Merged

test: split unit_tests.cpp with TCP messaging fixture#1092
kcenon merged 1 commit into
developfrom
feat/issue-1088-split-unit-tests

Conversation

@kcenon

@kcenon kcenon commented May 1, 2026

Copy link
Copy Markdown
Owner

Closes #1088

Summary

  • Add tests/support/messaging_loopback_fixture for ephemeral-port TCP messaging tests
  • Split unit_tests.cpp into per-concern files under tests/unit/ and tests/stress/
  • Register parallel-safe test executables in tests/CMakeLists.txt
  • Remove tests/unit_tests.cpp

Test Plan

  • ctest -j 8 passes (3 consecutive green runs locally)
  • All 22 TEST_F + 2 TEST cases preserved (no behavior loss)
  • No port literals in new test files (verified by grep)

Replace the 962-line monolithic tests/unit_tests.cpp with per-concern test
executables under tests/unit/ and tests/stress/, all backed by a shared
messaging_loopback_fixture in tests/support/ that requests an OS-assigned
ephemeral TCP port for every test. This removes the port-collision risk
that previously forced suite-level test registration to be commented out.

* tests/support/messaging_loopback_fixture.{h,cpp}:
  - Free functions pick_ephemeral_port() and wait_for_ready() plus the
    is_sanitizer_run() guard the legacy fixture used.
  - Trivial messaging_loopback_fixture base derived from ::testing::Test
    so tests can pick the helper they need.
  - Distinct from hermetic_transport_fixture, which is wired for HTTP/2,
    gRPC, QUIC, and WebSocket peers (TLS-bearing).

* tests/unit/messaging_server_lifecycle_test.cpp: ServerConstruction,
  ServerStartStop, ServerMultipleStartStop, ServerPortAlreadyInUse,
  DoubleStartReturnsAlreadyExistsError.

* tests/unit/messaging_client_lifecycle_test.cpp: ClientConstruction,
  ClientConnectToNonExistentServer, ClientServerBasicConnection,
  MultipleClientsConnection, SendWithoutConnection.

* tests/unit/messaging_transfer_test.cpp: BasicMessageTransfer,
  LargeMessageTransfer, MultipleMessageTransfer.

* tests/unit/messaging_server_session_test.cpp: ServerStopWhileClientsConnected,
  CleanupDeadSessionsOnNewConnection, WaitForStopIsCallableWhileRunning,
  WaitForStopOnNonRunningServerReturnsImmediately. Named with the
  messaging_server_session_ prefix to avoid colliding with the existing
  tests/unit/messaging_session_test.cpp which targets messaging_session.

* tests/unit/messaging_id_test.cpp: ServerIdReturnsConstructorValue,
  ServerIdEmptyStringIsValid, SetAndGetMonitor.

* tests/stress/messaging_stress_test.cpp: NetworkStressTest.RapidConnection-
  Disconnection and NetworkStressTest.ConcurrentClients, kept as bare TEST()
  cases so the original test names survive.

* tests/CMakeLists.txt: introduce a network_add_messaging_test() helper that
  links network::test_support and inherits the optional WITH_* defines the
  legacy network_unit_tests target carried, then registers the six new
  executables one per file. Each one calls add_test (via gtest_discover_tests)
  because the ephemeral fixture removes the parallel-port conflict.

* tests/support/CMakeLists.txt: include messaging_loopback_fixture.cpp in
  the network_test_support archive.

* scripts/build.sh: switch the test step to ctest now that there is no
  single network_unit_tests binary.

Closes #1088
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Metric Value
Line Coverage 69.2%
Branch Coverage 34.4%
Target 80% lines / 70% branches
Coverage Details

Full HTML report is available as a build artifact.

@kcenon kcenon merged commit b3d8bd2 into develop May 1, 2026
15 checks passed
@kcenon kcenon deleted the feat/issue-1088-split-unit-tests branch May 1, 2026 14:07
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