Add TCP and UDP network unit tests#162
Add TCP and UDP network unit tests#162222448082Ashen wants to merge 1 commit intothoth-tech:mainfrom
Conversation
Extend network unit tests to improve coverage and handle asynchronous network activity. Added a wait_for_network_condition helper (uses current_ticks, check_network_activity, delay) and includes (<functional>, utils.h). Added two new tests in unit_test_network.cpp: "tcp messages can flow both ways" (port 3010) and "udp messages can flow both ways" (port 3011) which verify bidirectional messaging between server and client, message contents, and proper cleanup of connections/servers. Also added CTest temporary output files (CTestCostData.txt, LastTest.log, LastTestsFailed.log) produced by the test run.
kyriesk
left a comment
There was a problem hiding this comment.
Positive Aspects
- The test is well-structured and covers the full TCP message flow in both directions, which is essential for robust networking.
- The test cleans up resources (servers, connections) at the end, which helps maintain test isolation and reliability.
Fail Test Identified
Line 275
FAILED:
REQUIRE( accept_new_connection(server) )
with expansion:
false
Issue: This assertion is failing, indicating that the server did not accept a new connection from the client. This can be due to timing issues, where the client connects before the server is fully ready, or the server does not detect the new connection in time.
Suggestion: Consider wrapping accept_new_connection(server) in a retry loop or use wait_for_network_condition to repeatedly check until the connection is accepted or a timeout occurs. This will make the test more robust against timing-related flakiness.
Additional Suggestions:
Add more detailed logging or error messages when the connection is not accepted, to help diagnose whether the issue is on the client or server side.
If possible, verify that the client is actually attempting to connect and that the server is listening on the expected port before making assertions.
Description
This PR expands networking unit test coverage by porting core TCP and UDP message-flow checks from sktest into the Catch2 unit test suite.
Changes included:
Motivation:
Dependencies:
Fixes # (issue)
Type of change
How Has This Been Tested?
Build and discovery:
Networking test execution:
ctest --test-dir projects/cmake/build-ninja -R "network|server|communicate|tcp messages|udp messages" --output-on-failure
Current environment result:
Testing Checklist
Checklist