From bd06798fd3b80e458cb717ae2e7b66b798728c2e Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Sun, 14 Sep 2025 11:38:43 -0400 Subject: [PATCH] Remove test_http_handler and test_server_connection_return --- CMakeLists.txt | 10 --- tests/test_http_handler.cpp | 60 ------------- tests/test_server_connection_return.cpp | 108 ------------------------ 3 files changed, 178 deletions(-) delete mode 100644 tests/test_http_handler.cpp delete mode 100644 tests/test_server_connection_return.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e3b2da..ed87eef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,16 +197,6 @@ target_link_libraries(test_commit_request doctest_impl weaseldb_sources_debug target_include_directories(test_commit_request PRIVATE tests) target_compile_options(test_commit_request PRIVATE -UNDEBUG) -add_executable(test_http_handler tests/test_http_handler.cpp) -target_link_libraries(test_http_handler doctest_impl weaseldb_sources_debug) -target_compile_options(test_http_handler PRIVATE -UNDEBUG) - -add_executable(test_server_connection_return - tests/test_server_connection_return.cpp) -target_link_libraries(test_server_connection_return doctest_impl - weaseldb_sources_debug) -target_compile_options(test_server_connection_return PRIVATE -UNDEBUG) - # Metrics system test add_executable(test_metric tests/test_metric.cpp) target_link_libraries(test_metric doctest_impl weaseldb_sources_debug) diff --git a/tests/test_http_handler.cpp b/tests/test_http_handler.cpp deleted file mode 100644 index df89ae8..0000000 --- a/tests/test_http_handler.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "arena.hpp" -#include "connection_handler.hpp" -#include "perfetto_categories.hpp" -#include -#include - -// Perfetto static storage for tests -PERFETTO_TRACK_EVENT_STATIC_STORAGE(); - -// Global variable needed by Connection -std::atomic activeConnections{0}; - -// Simple test helper since Connection has complex constructor requirements -struct TestConnectionData { - Arena arena; - std::string message_buffer; - void *user_data = nullptr; - - void append_message(std::string_view data) { message_buffer += data; } - - Arena &get_arena() { return arena; } - const std::string &getResponse() const { return message_buffer; } - void clearResponse() { message_buffer.clear(); } - void reset() { - arena.reset(); - message_buffer.clear(); - } -}; - -// Test helper to verify the new hook functionality -struct MockConnectionHandler : public ConnectionHandler { - bool write_progress_called = false; - bool write_buffer_drained_called = false; - - void on_write_progress(Ref &) override { - write_progress_called = true; - } - - void on_write_buffer_drained(Ref &) override { - write_buffer_drained_called = true; - } -}; - -TEST_CASE("ConnectionHandler hooks") { - SUBCASE("on_write_buffer_drained hook exists") { - MockConnectionHandler handler; - - // Verify hooks are available and can be overridden - CHECK_FALSE(handler.write_progress_called); - CHECK_FALSE(handler.write_buffer_drained_called); - - // Would normally be called by Server during write operations - Ref null_conn; - handler.on_write_progress(null_conn); - handler.on_write_buffer_drained(null_conn); - - CHECK(handler.write_progress_called); - CHECK(handler.write_buffer_drained_called); - } -} diff --git a/tests/test_server_connection_return.cpp b/tests/test_server_connection_return.cpp deleted file mode 100644 index e16d53e..0000000 --- a/tests/test_server_connection_return.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "../src/thread_pipeline.hpp" -#include "config.hpp" -#include "connection.hpp" -#include "perfetto_categories.hpp" -#include "server.hpp" -#include -#include -#include - -// Perfetto static storage for tests -PERFETTO_TRACK_EVENT_STATIC_STORAGE(); - -struct Message { - Ref conn; - std::string data; - bool done; -}; - -struct EchoHandler : public ConnectionHandler { -private: - StaticThreadPipeline &pipeline; - -public: - explicit EchoHandler( - StaticThreadPipeline - &pipeline) - : pipeline(pipeline) {} - - void on_data_arrived(std::string_view data, - Ref &conn_ptr) override { - assert(conn_ptr); - auto guard = pipeline.push(1, true); - for (auto &message : guard.batch) { - message.conn = std::move(conn_ptr); - message.data = data; - message.done = false; - } - } -}; - -TEST_CASE( - "Server correctly handles connection ownership transfer via pipeline") { - weaseldb::Config config; - config.server.io_threads = 1; - - StaticThreadPipeline pipeline{10}; - EchoHandler handler{pipeline}; - auto echoThread = std::thread{[&]() { - for (;;) { - auto guard = pipeline.acquire<0, 0>(); - for (auto &message : guard.batch) { - bool done = message.done; - if (done) { - return; - } - assert(message.conn); - message.conn->append_message(message.data); - } - } - }}; - - // Create server with NO listen sockets (empty vector) - auto server = Server::create(config, handler, {}); - - std::thread server_thread([&server]() { server->run(); }); - - // Create local connection - int client_fd = server->create_local_connection(); - REQUIRE(client_fd > 0); - - // Write some test data - const char *test_message = "Hello, World!"; - ssize_t bytes_written; - do { - bytes_written = write(client_fd, test_message, std::strlen(test_message)); - } while (bytes_written == -1 && errno == EINTR); - REQUIRE(bytes_written == std::strlen(test_message)); - - // Read the echoed response - char buffer[1024] = {0}; - ssize_t bytes_read; - do { - bytes_read = read(client_fd, buffer, sizeof(buffer) - 1); - } while (bytes_read == -1 && errno == EINTR); - if (bytes_read == -1) { - perror("read failed"); - } - REQUIRE(bytes_read == std::strlen(test_message)); - - // Verify we got back exactly what we sent - CHECK(std::string(buffer, bytes_read) == std::string(test_message)); - - // Cleanup - int e = close(client_fd); - if (e == -1 && errno != EINTR) { - perror("close client_fd"); - std::abort(); - } - server->shutdown(); - server_thread.join(); - { - auto guard = pipeline.push(1, true); - for (auto &message : guard.batch) { - message.done = true; - } - } - echoThread.join(); -}