From b98b10c07236cd37d96f14e4a220af11dc8a0fc6 Mon Sep 17 00:00:00 2001 From: Matthew Zipkin Date: Fri, 26 Jun 2026 15:32:41 -0400 Subject: [PATCH] test: introduce a worker thread in http socket error test --- src/test/httpserver_tests.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/test/httpserver_tests.cpp b/src/test/httpserver_tests.cpp index 8e66d3d4c4c..ff1eb22d703 100644 --- a/src/test/httpserver_tests.cpp +++ b/src/test/httpserver_tests.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -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 height{0}; HTTPServer server{[&](std::shared_ptr 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();