From c53c40f7eb0b4d218392a04fdeff1ca213c3df0e Mon Sep 17 00:00:00 2001 From: nguyenhoangthuan99 Date: Thu, 12 Sep 2024 15:41:32 +0700 Subject: [PATCH 1/7] Fix create log folder before logging --- engine/main.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/engine/main.cc b/engine/main.cc index 1450d887c..b7a4df5c0 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -30,6 +30,7 @@ void RunServer() { LOG_INFO << "Host: " << config.apiServerHost << " Port: " << config.apiServerPort << "\n"; // Create logs/ folder and setup log to file + std::filesystem::create_directory(config.logFolderPath); std::filesystem::create_directory(config.logFolderPath + "/" + cortex_utils::logs_folder); trantor::FileLogger asyncFileLogger; @@ -41,7 +42,7 @@ void RunServer() { [&](const char* msg, const uint64_t len) { asyncFileLogger.output_(msg, len); }, - [&]() { asyncFileLogger.flush(); }); + [&]() { asyncFileLogger.flush_(); }); // Number of cortex.cpp threads // if (argc > 1) { // thread_num = std::atoi(argv[1]); @@ -158,6 +159,9 @@ int main(int argc, char* argv[]) { return 0; } else { auto config = file_manager_utils::GetCortexConfig(); + std::filesystem::create_directory(config.logFolderPath); + std::filesystem::create_directory(config.logFolderPath + "/" + + cortex_utils::logs_folder); trantor::FileLogger asyncFileLogger; asyncFileLogger.setFileName(config.logFolderPath + "/" + cortex_utils::logs_cli_base_name); @@ -168,7 +172,7 @@ int main(int argc, char* argv[]) { [&](const char* msg, const uint64_t len) { asyncFileLogger.output_(msg, len); }, - [&]() { asyncFileLogger.flush(); }); + [&]() { asyncFileLogger.flush_(); }); CommandLineParser clp; clp.SetupCommand(argc, argv); return 0; From 091c4e4312970994999f529900308b9f5d64e480 Mon Sep 17 00:00:00 2001 From: nguyenhoangthuan99 Date: Thu, 12 Sep 2024 15:44:17 +0700 Subject: [PATCH 2/7] Fix create log folder before logging --- engine/main.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/main.cc b/engine/main.cc index b7a4df5c0..1e7d05bf3 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -42,7 +42,7 @@ void RunServer() { [&](const char* msg, const uint64_t len) { asyncFileLogger.output_(msg, len); }, - [&]() { asyncFileLogger.flush_(); }); + [&]() { asyncFileLogger.flush(); }); // Number of cortex.cpp threads // if (argc > 1) { // thread_num = std::atoi(argv[1]); @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) { [&](const char* msg, const uint64_t len) { asyncFileLogger.output_(msg, len); }, - [&]() { asyncFileLogger.flush_(); }); + [&]() { asyncFileLogger.flush(); }); CommandLineParser clp; clp.SetupCommand(argc, argv); return 0; From c0495e5a69484291f3134f57bec4f3f8a4d9ec4e Mon Sep 17 00:00:00 2001 From: nguyenhoangthuan99 Date: Thu, 12 Sep 2024 16:28:19 +0700 Subject: [PATCH 3/7] Fix create log folder before logging --- engine/main.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/main.cc b/engine/main.cc index 1e7d05bf3..b779f1ac0 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -31,8 +31,8 @@ void RunServer() { // Create logs/ folder and setup log to file std::filesystem::create_directory(config.logFolderPath); - std::filesystem::create_directory(config.logFolderPath + "/" + - cortex_utils::logs_folder); + std::filesystem::create_directory(std::filesystem::path(config.logFolderPath) / + std::filesystem::path(cortex_utils::logs_folder)); trantor::FileLogger asyncFileLogger; asyncFileLogger.setFileName(config.logFolderPath + "/" + cortex_utils::logs_base_name); @@ -160,8 +160,8 @@ int main(int argc, char* argv[]) { } else { auto config = file_manager_utils::GetCortexConfig(); std::filesystem::create_directory(config.logFolderPath); - std::filesystem::create_directory(config.logFolderPath + "/" + - cortex_utils::logs_folder); + std::filesystem::create_directory(std::filesystem::path(config.logFolderPath) / + std::filesystem::path(cortex_utils::logs_folder)); trantor::FileLogger asyncFileLogger; asyncFileLogger.setFileName(config.logFolderPath + "/" + cortex_utils::logs_cli_base_name); From 45565ad4c3b6c8d305838a0c8fcbb5b102fa556c Mon Sep 17 00:00:00 2001 From: nguyenhoangthuan99 Date: Thu, 12 Sep 2024 16:32:30 +0700 Subject: [PATCH 4/7] Fix create log folder before logging --- engine/main.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/engine/main.cc b/engine/main.cc index 6f6ead9bf..38dd3791b 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -31,8 +31,7 @@ void RunServer() { << " Port: " << config.apiServerPort << "\n"; // Create logs/ folder and setup log to file - std::filesystem::create_directory(config.logFolderPath); - std::filesystem::create_directory(std::filesystem::path(config.logFolderPath) / + std::filesystem::create_directories(std::filesystem::path(config.logFolderPath) / std::filesystem::path(cortex_utils::logs_folder)); trantor::FileLogger asyncFileLogger; asyncFileLogger.setFileName(config.logFolderPath + "/" + @@ -161,8 +160,7 @@ int main(int argc, char* argv[]) { return 0; } else { auto config = file_manager_utils::GetCortexConfig(); - std::filesystem::create_directory(config.logFolderPath); - std::filesystem::create_directory(std::filesystem::path(config.logFolderPath) / + std::filesystem::create_directories(std::filesystem::path(config.logFolderPath) / std::filesystem::path(cortex_utils::logs_folder)); trantor::FileLogger asyncFileLogger; asyncFileLogger.setFileName(config.logFolderPath + "/" + From a8859bc1f6b1f55176e0561bfe0db8abf5907117 Mon Sep 17 00:00:00 2001 From: nguyenhoangthuan99 Date: Thu, 12 Sep 2024 17:42:17 +0700 Subject: [PATCH 5/7] add end to end test for server start --- engine/e2e-test/main.py | 1 + engine/e2e-test/test_cli_server_start.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 engine/e2e-test/test_cli_server_start.py diff --git a/engine/e2e-test/main.py b/engine/e2e-test/main.py index d59466d29..88b806fb6 100644 --- a/engine/e2e-test/main.py +++ b/engine/e2e-test/main.py @@ -4,6 +4,7 @@ from test_cli_engine_install import TestCliEngineInstall from test_cli_engine_list import TestCliEngineList from test_cli_engine_uninstall import TestCliEngineUninstall +from test_cli_server_start import TestCliServerStart if __name__ == "__main__": pytest.main([__file__, "-v"]) diff --git a/engine/e2e-test/test_cli_server_start.py b/engine/e2e-test/test_cli_server_start.py new file mode 100644 index 000000000..abe236cd0 --- /dev/null +++ b/engine/e2e-test/test_cli_server_start.py @@ -0,0 +1,24 @@ +import platform +import os +import pytest, requests +from test_runner import run +from test_runner import start_server, stop_server + + +class TestCliServerStart: + + @pytest.fixture(autouse=True) + def setup_and_teardown(self): + # Setup + success = start_server() + if not success: + raise Exception("Failed to start server") + + yield + + # Teardown + stop_server() + + def test_server_start_cli_run_successfully(self): + response = requests.get("http://localhost:3928/healthz") + assert response.status_code == 200 From 0af3ac5e5097f01ed427dab055be4ed84f8e7239 Mon Sep 17 00:00:00 2001 From: nguyenhoangthuan99 Date: Thu, 12 Sep 2024 18:32:52 +0700 Subject: [PATCH 6/7] add end to end test for log folder created --- engine/e2e-test/main.py | 1 + engine/e2e-test/test_create_log_folder.py | 24 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 engine/e2e-test/test_create_log_folder.py diff --git a/engine/e2e-test/main.py b/engine/e2e-test/main.py index 88b806fb6..9ef27c8dc 100644 --- a/engine/e2e-test/main.py +++ b/engine/e2e-test/main.py @@ -5,6 +5,7 @@ from test_cli_engine_list import TestCliEngineList from test_cli_engine_uninstall import TestCliEngineUninstall from test_cli_server_start import TestCliServerStart +from test_create_log_folder import TestCreateLogFolder if __name__ == "__main__": pytest.main([__file__, "-v"]) diff --git a/engine/e2e-test/test_create_log_folder.py b/engine/e2e-test/test_create_log_folder.py new file mode 100644 index 000000000..e1247a29e --- /dev/null +++ b/engine/e2e-test/test_create_log_folder.py @@ -0,0 +1,24 @@ +import platform +import os +from pathlib import Path +import pytest, requests +from test_runner import run +from test_runner import start_server, stop_server + + +class TestCreateLogFolder: + @pytest.fixture(autouse=True) + def setup_and_teardown(self): + # Setup + success = start_server() + if not success: + raise Exception("Failed to start server") + + yield + + # Teardown + stop_server() + + def test_create_log_folder_run_successfully(self): + root = Path.home() + assert os.path.exists(root / "cortexcpp" / "logs") \ No newline at end of file From d71d7916198df82f7ace34ab0e1c1684a6ab30a9 Mon Sep 17 00:00:00 2001 From: nguyenhoangthuan99 <35255081+nguyenhoangthuan99@users.noreply.github.com> Date: Fri, 13 Sep 2024 08:08:25 +0700 Subject: [PATCH 7/7] Update test_create_log_folder.py --- engine/e2e-test/test_create_log_folder.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/engine/e2e-test/test_create_log_folder.py b/engine/e2e-test/test_create_log_folder.py index e1247a29e..3d0236cd7 100644 --- a/engine/e2e-test/test_create_log_folder.py +++ b/engine/e2e-test/test_create_log_folder.py @@ -1,7 +1,7 @@ import platform import os from pathlib import Path -import pytest, requests +import pytest, requests, shutil from test_runner import run from test_runner import start_server, stop_server @@ -10,6 +10,9 @@ class TestCreateLogFolder: @pytest.fixture(autouse=True) def setup_and_teardown(self): # Setup + root = Path.home() + if os.path.exists(root / "cortexcpp" / "logs"): + shutil.rmtree(root / "cortexcpp" / "logs") success = start_server() if not success: raise Exception("Failed to start server") @@ -21,4 +24,4 @@ def setup_and_teardown(self): def test_create_log_folder_run_successfully(self): root = Path.home() - assert os.path.exists(root / "cortexcpp" / "logs") \ No newline at end of file + assert os.path.exists(root / "cortexcpp" / "logs")