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

This commit is contained in:
Антон
2025-10-06 17:57:05 +03:00
parent 89d7f62f28
commit 139cf01557
4 changed files with 49 additions and 2 deletions
+10 -2
View File
@@ -13,7 +13,7 @@ set(Boost_USE_MULTITHREADED ON)
set(Boost_INCLUDE_DIR ${BOOST_ROOT})
set(Boost_LIBRARY_DIR "${BOOST_ROOT}/stage/lib")
find_package(Boost 1.88.0 REQUIRED COMPONENTS filesystem json log)
find_package(Boost 1.88.0 REQUIRED COMPONENTS filesystem json log system filesystem)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif ()
@@ -50,9 +50,17 @@ add_executable(App ./src/main.cpp
./src/endpoints_handlers/AuthLogoutExecutor.h
./src/exceptions/session_exception.cpp
./src/exceptions/session_exception.h
src/log/Log.h
src/log/Log.cpp
)
target_link_libraries(App PRIVATE Boost::boost Boost::json Threads::Threads mysql::concpp)
target_link_libraries(App PRIVATE Boost::boost
Boost::json
Boost::log
Boost::system
Boost::filesystem
Threads::Threads
mysql::concpp)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
namespace logging = boost::log;
namespace uad
{
void InitLogs()
{
logging::add_file_log(
logging::keywords::file_name = "app_%Y-%m-%d_%H-%M-%S.log", // Имя файла с timestamp
logging::keywords::rotation_size = 10 * 1024 * 1024, // Ротация при достижении 10 МБ
logging::keywords::time_based_rotation =
logging::sinks::file::rotation_at_time_point(0, 0, 0), // Ротация каждый день в полночь
logging::keywords::format = "[%TimeStamp%] [%Severity%]: %Message%" // Формат записи
);
}
}
+6
View File
@@ -0,0 +1,6 @@
#pragma once
namespace uad
{
void InitLogs();
}
+12
View File
@@ -14,11 +14,15 @@
#include <string>
#include <thread>
#include <vector>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include "./session/WebsocketSession.h"
#include "./listener/Listener.h"
#include "./db/mysql_connector.h"
#include "entities/user.h"
#include "log/Log.h"
namespace beast = boost::beast;
namespace http = beast::http;
@@ -28,6 +32,7 @@ using tcp = boost::asio::ip::tcp;
using namespace uad;
using namespace std;
using namespace std::string_literals;
namespace logging = boost::log;
int main(int argc, char* argv[])
{
@@ -44,6 +49,11 @@ int main(int argc, char* argv[])
auto const threads = std::max<int>(1, std::atoi(argv[4]));
string mysql_credentials = argv[5];
InitLogs();
// Добавление общих атрибутов (включая время)
logging::add_common_attributes();
uad::SetMySqlSession(new mysqlx::Session(mysql_credentials));
net::io_context ioc{threads};
@@ -53,6 +63,8 @@ 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(error) << "Приложение запущено";
std::vector<std::thread> v;
v.reserve(threads - 1);
for (auto i = threads - 1; i > 0; --i)