Remove test_http_handler and test_server_connection_return
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
#include "arena.hpp"
|
||||
#include "connection_handler.hpp"
|
||||
#include "perfetto_categories.hpp"
|
||||
#include <atomic>
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
// Perfetto static storage for tests
|
||||
PERFETTO_TRACK_EVENT_STATIC_STORAGE();
|
||||
|
||||
// Global variable needed by Connection
|
||||
std::atomic<int> 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<Connection> &) override {
|
||||
write_progress_called = true;
|
||||
}
|
||||
|
||||
void on_write_buffer_drained(Ref<Connection> &) 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<Connection> 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);
|
||||
}
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
#include "../src/thread_pipeline.hpp"
|
||||
#include "config.hpp"
|
||||
#include "connection.hpp"
|
||||
#include "perfetto_categories.hpp"
|
||||
#include "server.hpp"
|
||||
#include <cstring>
|
||||
#include <doctest/doctest.h>
|
||||
#include <thread>
|
||||
|
||||
// Perfetto static storage for tests
|
||||
PERFETTO_TRACK_EVENT_STATIC_STORAGE();
|
||||
|
||||
struct Message {
|
||||
Ref<Connection> conn;
|
||||
std::string data;
|
||||
bool done;
|
||||
};
|
||||
|
||||
struct EchoHandler : public ConnectionHandler {
|
||||
private:
|
||||
StaticThreadPipeline<Message, WaitStrategy::WaitIfStageEmpty, 1> &pipeline;
|
||||
|
||||
public:
|
||||
explicit EchoHandler(
|
||||
StaticThreadPipeline<Message, WaitStrategy::WaitIfStageEmpty, 1>
|
||||
&pipeline)
|
||||
: pipeline(pipeline) {}
|
||||
|
||||
void on_data_arrived(std::string_view data,
|
||||
Ref<Connection> &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<Message, WaitStrategy::WaitIfStageEmpty, 1> 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();
|
||||
}
|
||||
Reference in New Issue
Block a user