Skip to content

tests: split unit_tests.cpp with TCP messaging fixture #1088

Description

@kcenon

What

Split the 962-line monolithic tests/unit_tests.cpp into per-concern files using a shared fixture base for the existing TCP messaging_server/messaging_client flow.

Part of #1083.

Current state

  • tests/unit_tests.cpp — 962 lines, 22 TEST_F(NetworkTest, ...) cases plus 2 free TEST(NetworkStressTest, ...) cases, all reusing one ad-hoc NetworkTest fixture that hard-codes ports.
  • tests/CMakeLists.txt already disables suite-level registration: # Don't add suite-level test to prevent port conflicts during parallel execution.
  • tests/support/hermetic_transport_fixture (Issue infra: hermetic transport fixture for HTTP/2 / QUIC / WebSocket / gRPC unit tests #1060) exists but is wired for HTTP/2, gRPC, QUIC, WebSocket — not the plain TCP messaging_* flow used by NetworkTest.

Out of scope

  • tests/unit_tests_original.cpp (572 lines, separate cleanup decision)
  • The non-TCP test files under tests/test_*.cpp and tests/unit/ (already split)

Why

Parallel test execution is currently disabled because the monolithic file's hard-coded ports collide. Splitting into per-concern files plus a fixture that requests an OS-assigned ephemeral port (:0) lets ctest -j N run safely and lets failures localize to the file under test.

Where

  • tests/unit_tests.cpp (split source)
  • tests/support/ (new TCP messaging fixture)
  • tests/CMakeLists.txt (register new executables)

How

Technical approach

  1. Add tests/support/messaging_loopback_fixture.{h,cpp} — a GTest fixture that:
    • constructs messaging_server bound to 127.0.0.1:0,
    • exposes the kernel-assigned port to the test,
    • tears down server + clients in TearDown().
  2. Split unit_tests.cpp into roughly:
    • tests/unit/messaging_server_lifecycle_test.cpp (ServerConstruction/StartStop/PortInUse/DoubleStart)
    • tests/unit/messaging_client_lifecycle_test.cpp (ClientConstruction/ConnectToNonExistentServer/SendWithoutConnection)
    • tests/unit/messaging_transfer_test.cpp (BasicMessageTransfer/LargeMessageTransfer/MultipleMessageTransfer)
    • tests/unit/messaging_session_test.cpp (ServerStopWhileClientsConnected/CleanupDeadSessions/WaitForStop*)
    • tests/unit/messaging_id_test.cpp (ServerIdReturnsConstructorValue/EmptyStringIsValid/SetAndGetMonitor)
    • tests/stress/messaging_stress_test.cpp (RapidConnectionDisconnection, ConcurrentClients)
  3. Each new file uses the fixture base; ports come from the fixture, never literals.
  4. Update tests/CMakeLists.txt — register one add_executable per file, link network_system + GTest::gtest_main + Threads + test_support, register each via add_test.
  5. Delete tests/unit_tests.cpp after successful migration.

Acceptance criteria

  • No port literals remain in the new test files (verified by grep)
  • ctest -j 8 passes locally and on CI without flakes (3 consecutive green runs)
  • tests/unit_tests.cpp removed
  • All 22 TEST_F + 2 TEST cases preserved (no behavior loss)
  • CI green on PR

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions