WIP: test: sock_tests: Handle partial reads in send_and_receive

bitcoin/bitcoin: PR #36846

1 suggestion

Optional improvements

Link

[suggestion] · A short send can leave the receive loop waiting indefinitely

An unlikely short positive Send could make this test block waiting for unsent bytes; no run or reproducer producing that send result was found.

Location: src/test/sock_tests.cpp:134 (head).

Details and suggested fix

BOOST_CHECK_EQUAL records a send-count mismatch but continues. If Send returns 1–3 bytes, the new loop can consume those bytes and then block waiting for the remainder: these sockets are blocking, the sender remains open, and nothing sends the missing suffix. BOOST_REQUIRE_GT cannot prevent that wait because it executes only after Recv returns. Previously, the single receive could return the available bytes and report a count mismatch without waiting for more. Change the send assertion to BOOST_REQUIRE_EQUAL(sender.Send(msg, msg_len, 0), msg_len); so the test stops when the prerequisite for receiving four bytes is not met.


Coverage details