Подготовка интеграционного теста

This commit is contained in:
Антон
2025-10-07 10:59:06 +03:00
parent 5fcad355d1
commit 38a8d5effd
6 changed files with 12 additions and 126 deletions
+2 -1
View File
@@ -3,7 +3,7 @@ project(UpAndDown)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-D_WIN32_WINNT=0x0602)
if(POLICY CMP0167)
cmake_policy(SET CMP0167 OLD)
endif()
@@ -48,6 +48,7 @@ add_executable(App ./src/main.cpp
./src/DAO/MemoryAuthDAO.cpp
./src/DAO/MemoryAuthDAO.h
./src/endpoints_handlers/AuthLogoutExecutor.h
./src/endpoints_handlers/AuthLoginExecutor.h
./src/exceptions/session_exception.cpp
./src/exceptions/session_exception.h
src/log/Log.h
-72
View File
@@ -1,72 +0,0 @@
#include "Listener.h"
namespace uad
{
Listener::Listener(boost::asio::io_context& ioc,
boost::asio::ip::tcp::endpoint endpoint,
const std::shared_ptr<const std::string>& doc_root)
: ioc_(ioc), acceptor_(net::make_strand(ioc)), doc_root_(doc_root)
{
beast::error_code ec;
acceptor_.open(endpoint.protocol(), ec);
if (ec)
{
uad::Fail(ec, "open");
return;
}
acceptor_.set_option(net::socket_base::reuse_address(true), ec);
if (ec)
{
uad::Fail(ec, "set_option");
return;
}
acceptor_.bind(endpoint, ec);
if (ec)
{
uad::Fail(ec, "bind");
return;
}
acceptor_.listen(
net::socket_base::max_listen_connections, ec);
if (ec)
{
uad::Fail(ec, "listen");
return;
}
}
void Listener::Run()
{
DoAccept();
}
void Listener::DoAccept()
{
acceptor_.async_accept(
net::make_strand(ioc_),
beast::bind_front_handler(
&Listener::OnAccept,
shared_from_this()));
}
void Listener::OnAccept(beast::error_code ec, tcp::socket socket)
{
if (ec)
{
uad::Fail(ec, "accept");
return;
}
else
{
std::make_shared<uad::Session>(
std::move(socket),
doc_root_)->Run();
}
DoAccept();
}
}
-45
View File
@@ -1,45 +0,0 @@
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/version.hpp>
#include <boost/asio/dispatch.hpp>
#include <boost/asio/strand.hpp>
#include <boost/config.hpp>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <vector>
#include "helpers.h"
#include "Session.h"
namespace uad
{
namespace beast = boost::beast;
namespace http = beast::http;
namespace net = boost::asio;
using tcp = boost::asio::ip::tcp;
class Listener : public std::enable_shared_from_this<Listener>
{
net::io_context& ioc_;
tcp::acceptor acceptor_;
std::shared_ptr<std::string const> doc_root_;
public:
Listener(
net::io_context& ioc,
tcp::endpoint endpoint,
std::shared_ptr<std::string const> const& doc_root);
void Run();
private:
void DoAccept();
void OnAccept(beast::error_code ec, tcp::socket socket);
};
}
+4 -1
View File
@@ -1,11 +1,12 @@
#pragma once
#include <boost/log/trivial.hpp>
#include <regex>
#include <boost/json.hpp>
#include <mysqlx/xdevapi.h>
#include <mysqlx/common/api.h>
#include <boost/uuid.hpp>
#include <boost/uuid.hpp>
#include "IExecutor.h"
#include "../DAO/IUserDAO.h"
#include "../DAO/IAuthDAO.h"
@@ -38,6 +39,8 @@ public:
using namespace boost::beast;
using namespace std::string_literals;
BOOST_LOG_TRIVIAL(info) << "POST /api/v1/Auth/Login - Request";
const auto body = req.body();
value req_json;
+1
View File
@@ -17,5 +17,6 @@ void InitLogs()
logging::sinks::file::rotation_at_time_point(0, 0, 0),
logging::keywords::format = "[%TimeStamp%] [%Severity%]: %Message%"
);
logging::add_common_attributes();
}
}
+3 -5
View File
@@ -1,10 +1,9 @@
#include <boost/log/trivial.hpp>
#ifdef WIN32
#include <sdkddkver.h>
#endif
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <algorithm>
#include <boost/asio/signal_set.hpp>
#include <boost/beast/core.hpp>
@@ -52,7 +51,6 @@ int main(int argc, char* argv[])
InitLogs();
// Добавление общих атрибутов (включая время)
logging::add_common_attributes();
uad::SetMySqlSession(new mysqlx::Session(mysql_credentials));
@@ -63,7 +61,7 @@ int main(int argc, char* argv[])
net::signal_set signals(ioc, SIGINT, SIGTERM);
signals.async_wait([&](beast::error_code const&, int) { ioc.stop(); });
BOOST_LOG_TRIVIAL(info) << "Приложение запущено";
BOOST_LOG_TRIVIAL(info) << "Приложение запущено2";
std::vector<std::thread> v;
v.reserve(threads - 1);