Addresses review suggestions left (all of them made by ryanofsky) in the now-merged PRs #298 and #310.
These are non-critical test cleanups (naming, simplification, comments, etc.) with zero changes to library code.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--021abf342d371248e50ceaed478a90ca-->
See the guideline and AI policy for information on the review process.
| Type | Reviewers |
|---|---|
| ACK | ryanofsky |
If your review is incorrectly listed, please copy-paste <code><!--meta-tag:bot-skip--></code> into the comment that the bot should ignore.
<!--5faf32d7da4f0f540f40219e4f7537a3-->
Use the existing `SocketPair()` helper directly in each test instead of the
`init_sockets` callback and fd members, which nothing else in the class used.
Move it to a common.h file. The connect_tests copy previously didn't log
messages, now it does through the shared version.
Unnecessary since the tests are inside the mp namespace.
The conditional served no purpose and leaked the descriptor when `recv()`
failed or returned zero.
15 | + 16 | +//! Default event loop log handler used by tests. Logs all messages and throws 17 | +//! on errors so calling code can assert on them. 18 | +inline void DefaultLogHandler(LogMessage log) 19 | +{ 20 | + KJ_LOG(INFO, log.level, log.message);
In commit "test: share DefaultLogHandler between test files" (038d33eb31eb0d5742a27caeb0c5b244f0f794a1)
Looks like test.cpp is another place this could be used. It would also be nice to take the comment there about showing log output with mptest --verbose
37 | @@ -38,17 +38,17 @@ constexpr auto FAILURE_TIMEOUT = std::chrono::seconds{30}; 38 | class TestSetup 39 | { 40 | public: 41 | - mp::EventLoop* m_loop; 42 | - std::optional<mp::EventLoopRef> m_loop_ref; 43 | + EventLoop* m_loop;
In commit "test: drop mp:: prefixes in connect tests" (44bc4630bc18bb03977a3616bf979fb2b3192f54)
Note: looks like there are a few remaining mp:: prefixes that could be dropped in other test files, but reasonable to limit commit to this file
186 | - recv(connection_fd, buf, sizeof(buf), 0); 187 | - 188 | - if (bytes_received > 0) { 189 | - close(connection_fd); 190 | - } 191 | + recv(connection_fd, buf, sizeof(buf), 0);
In commit "test: close sockets unconditionally and check errors with KJ_SYSCALL" (b9c36c617518c0026f3b8c35014415b7437f6b8a)
Would be nice to capture errors here with KJ_SYSCALL(recv(server_fd, buf, sizeof(buf), 0)); or KJ_SYSCALL(bytes_received = recv(server_fd, buf, sizeof(buf), 0)); or KJ_SYSCALL(bytes_received = recv(...), "receiving client handshake");
181 | @@ -186,14 +182,10 @@ KJ_TEST("ConnectStream throws when a connection accepted from a listener disconn
182 | int connection_fd = accept(server_fd, nullptr, nullptr);
183 |
184 | if (connection_fd >= 0) {
In commit "test: close sockets unconditionally and check errors with KJ_SYSCALL" (b9c36c617518c0026f3b8c35014415b7437f6b8a)
Seems probably best to fail if accept fails:
int connection_fd;
KJ_SYSCALL(connection_fd = accept(server_fd, nullptr, nullptr));
Code review ACK c39c7850c663d1915ae2478dc53f2c7b690504db. Thanks for the followup!
0 | @@ -1,6 +1,7 @@ 1 | // Copyright (c) The Bitcoin Core developers 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | +#include "common.h" 5 | #include "unixlistener.h"
In commit "test: share DefaultLogHandler between test files" (038d33eb31eb0d5742a27caeb0c5b244f0f794a1)
For consistency would be good to use full include paths <mp/test/common.h> We should probably have a linter check for this