test(websocket): expand websocket_server.cpp coverage#1072
Merged
Conversation
Append 33 unit tests to tests/test_messaging_ws_server.cpp targeting public-API surfaces of messaging_ws_server reachable without a live WebSocket peer. Complements tests/unit/websocket_server_branch_test.cpp (added in #1059) by exercising additional angles: - ws_message struct as_text() / as_binary() round-trip and reference semantics used by invoke_message_callback() routing - ws_close_code enum value invariants per RFC 6455 Section 7.4 used by ws_connection::close(uint16_t, string_view) and on_close() - Constructor variations (c-string, std::string, string_view, substring string_view) and server_id() reference stability - Default-state queries via interfaces::i_websocket_server pointer (is_running, connection_count, stop) - get_connection() lookup for empty / 2048-char / IPv4-style ids on never-started server returning nullptr - get_all_connections() empty-vector stability on never-started server - broadcast_text / broadcast_binary with registered text / binary callbacks but no peers does not invoke the callbacks - Interface callback adapters: lambda capture is stored not invoked immediately for connection / disconnection / error - All five interface callbacks replaceable with default-constructed std::function (covers the empty-function adapter branch) - Multi-instance state isolation across 32 sequential constructions - Two servers with the same id are independent instances - wait_for_stop on never-started server returns under one second - stop_server idempotency across 10 calls and via interface pointer These tests are hermetic and rely solely on state reachable without a live io_context loop or TCP peer. The acceptance criteria of #1067 (line >= 80% / branch >= 70%) cannot be met from unit tests alone because the post-handshake frame I/O path requires an in-process WebSocket loopback fixture that does not exist yet; the gap is tracked under #953. Part of #1067 Part of #953
i_network_component::is_running() is declared protected in the base interface; only derived class messaging_ws_server publishes it publicly. Calling is_running() through std::shared_ptr<i_websocket_server> fails to compile with 'is protected within this context'. Replace the failing test with an interface-pointer stop()/connection_count() idempotency variant that uses only public surface.
Contributor
Coverage Report
Coverage DetailsFull HTML report is available as a build artifact. |
This was referenced Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Summary
Append 33 unit tests to
tests/test_messaging_ws_server.cppexercising further public-API surfaces ofmessaging_ws_serverfromsrc/http/websocket_server.cpp. Complements the existingtests/unit/websocket_server_branch_test.cpp(added in #1059) by covering different angles.Change Type
Affected Components
tests/test_messaging_ws_server.cpp— +388 LOC, +33 test cases (no source/build changes)Why
Part of #1067(and the parent epicPart of #953) — push narrow test-expansion across worst-coverage protocol files.Pre-PR baseline (2026-04-26 lcov):
src/http/websocket_server.cpp39.9% line / 19.7% branch. Existing tests cover the never-started state machine; this PR adds tests forws_messagedata helpers,ws_close_codeenum invariants, constructor variants, interface-pointer default queries, lookup edge cases, broadcast under registered callbacks, and lambda-capture semantics of the interface callback adapters.Where
ws_message::as_text/as_binaryws_close_codeenum invariants (RFC 6455)close(uint16_t, string_view)i_websocket_server::is_running/connection_count/stopget_connectionlookup edge casesget_all_connectionsstabilitywait_for_stopon never-startedstop_serveridempotencyHow
Implementation Approach
tests/test_messaging_ws_server.cpp(no parallel suite)MessagingWsServerTestGTest fixture<atomic>,<chrono>,<cstdint>,<limits>,<memory>,<string>,<string_view>,<system_error>,<utility>,<vector>, andinternal/websocket/websocket_protocol.hto the test-file includesCoverage Scope (Honest Assessment)
This PR does not reach the
>=80% line / >=70% branchacceptance criteria of #1067. The remaining gap is concentrated in the post-handshake code (do_start_implsuccess path pasttcp::acceptorconstruction,do_acceptasync completion,handle_new_connectionTCP+WebSocket wrapping,on_message/on_close/on_errorreachable only after a live HTTP/1.1 upgrade handshake). Those paths require an in-process WebSocket loopback fixture that does not currently exist in the test tree.Building the loopback fixture is a larger, separate piece of work (TCP loopback + complete WebSocket HTTP/1.1 upgrade + frame I/O) tracked under #953. This PR therefore uses
Part of #1067rather thanCloses #1067and the issue stays open.Test Plan
Breaking Changes
None — test-only addition.
Rollback Plan
Revert this single commit; no schema, ABI, or build surface affected.
Part of #1067
Part of #953