Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: create log folder before logging #1200

Merged
merged 9 commits into from
Sep 13, 2024
2 changes: 2 additions & 0 deletions engine/e2e-test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
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
from test_create_log_folder import TestCreateLogFolder

if __name__ == "__main__":
pytest.main([__file__, "-v"])
24 changes: 24 additions & 0 deletions engine/e2e-test/test_cli_server_start.py
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions engine/e2e-test/test_create_log_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import platform
import os
from pathlib import Path
import pytest, requests, shutil
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
nguyenhoangthuan99 marked this conversation as resolved.
Show resolved Hide resolved
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")

yield

# Teardown
stop_server()

def test_create_log_folder_run_successfully(self):
root = Path.home()
assert os.path.exists(root / "cortexcpp" / "logs")
6 changes: 4 additions & 2 deletions engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void RunServer() {
<< " Port: " << config.apiServerPort << "\n";

// Create logs/ folder and setup log to file
std::filesystem::create_directory(config.logFolderPath + "/" +
cortex_utils::logs_folder);
std::filesystem::create_directories(std::filesystem::path(config.logFolderPath) /
std::filesystem::path(cortex_utils::logs_folder));
trantor::FileLogger asyncFileLogger;
asyncFileLogger.setFileName(config.logFolderPath + "/" +
cortex_utils::logs_base_name);
Expand Down Expand Up @@ -160,6 +160,8 @@ int main(int argc, char* argv[]) {
return 0;
} else {
auto config = file_manager_utils::GetCortexConfig();
std::filesystem::create_directories(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);
Expand Down
Loading