test: introduce a worker thread in http socket error test
What changed, and why it matters
This is a test-only change. It updates a single unit test file to run the HTTP request handler on a separate worker thread instead of handling it synchronously. There is no change to production code, no security fix, and no vulnerability.
No action required. This is a routine test refactor with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies src/test/httpserver_tests.cpp in the http_socket_error_tests test case. It adds a ThreadPool, submits the reply logic as a work item to that pool, makes the shared height counter atomic to avoid a data race across threads, and stops the pool at the end of the test. This is purely a testing infrastructure adjustment.
Changed components
src/test/httpserver_tests.cppInspect captured patch +15 / −3
diff --git a/src/test/httpserver_tests.cpp b/src/test/httpserver_tests.cpp
index 8e66d3d4..ff1eb22d 100644
--- a/src/test/httpserver_tests.cpp
+++ b/src/test/httpserver_tests.cpp
@@ -8,6 +8,7 @@
#include <test/util/logging.h>
#include <test/util/setup_common.h>
#include <util/string.h>
+#include <util/threadpool.h>
#include <boost/test/unit_test.hpp>
@@ -631,11 +632,20 @@ BOOST_AUTO_TEST_CASE(http_server_socket_tests)
BOOST_AUTO_TEST_CASE(http_socket_error_tests)
{
+ // Create a tiny threadpool for the HTTPRequest handler
+ ThreadPool workers("http");
+ workers.Start(1);
+
// Hard-code the server's request handler to respond to each request with
- // an incremented block count.
- int height{0};
+ // an incremented block count. Handle the replies in the worker thread.
+ std::atomic<int> height{0};
HTTPServer server{[&](std::shared_ptr<HTTPRequest> req) {
- req->WriteReply(HTTP_OK, strprintf("height: %d\n", height++));
+ auto item = [req, &height]() {
+ const int h = height.fetch_add(1);
+ req->WriteReply(HTTP_OK, strprintf("height: %d\n", h));
+ };
+ // Can't call BOOST_REQUIRE from worker thread
+ Assert(workers.Submit(std::move(item)));
}};
// All replies will be the same size
@@ -742,6 +752,8 @@ BOOST_AUTO_TEST_CASE(http_socket_error_tests)
// Close the keep-alive connection
server.DisconnectAllClients();
+ workers.Stop();
+
server.InterruptNet();
server.JoinSocketsThreads();
server.StopListening();
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.