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

Move tests into system temporary directory #3290

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions test/include/graph_test/base_graph_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ class BaseGraphTest : public Test {
}

private:
void setDatabasePath() {
databasePath = TestHelper::appendKuzuRootPath(
TestHelper::TMP_TEST_DIR + getTestGroupAndName() + TestHelper::getMillisecondsSuffix());
}
void setDatabasePath() { databasePath = TestHelper::getTempDir(getTestGroupAndName()); }

public:
std::string databasePath;
Expand Down
25 changes: 22 additions & 3 deletions test/include/test_helper/test_helper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <filesystem>

#include "main/kuzu.h"

namespace kuzu {
Expand All @@ -21,8 +23,6 @@ class TestHelper {
static constexpr char E2E_TEST_FILES_DIRECTORY[] = TEST_FILES_DIR;
static constexpr char SCHEMA_FILE_NAME[] = "schema.cypher";
static constexpr char COPY_FILE_NAME[] = "copy.cypher";
static constexpr char PARQUET_TEMP_DATASET_PATH[] = "dataset/parquet_temp_";
static constexpr char TMP_TEST_DIR[] = "test/unittest_temp_";
static constexpr char TEST_ANSWERS_PATH[] = "test/answers";
static constexpr char TEST_STATEMENTS_PATH[] = "test/statements";
static constexpr char DEFAULT_CONN_NAME[] = "conn_default";
Expand All @@ -40,11 +40,30 @@ class TestHelper {
}

static std::string appendKuzuRootPath(const std::string& path) {
return KUZU_ROOT_DIRECTORY + std::string("/") + path;
if (std::filesystem::path(path).is_relative()) {
return KUZU_ROOT_DIRECTORY + std::string("/") + path;
} else {
return path;
}
}

static std::string getMillisecondsSuffix();

inline static std::filesystem::path getTempDir() {
return std::filesystem::temp_directory_path() / "kuzu";
}

inline static std::string getTempDir(const std::string& name) {
auto path = getTempDir() / (name + TestHelper::getMillisecondsSuffix());
std::filesystem::create_directories(path);
auto pathStr = path.string();
#ifdef _WIN32
// kuzu still doesn't support backslashes in paths on windows
std::replace(pathStr.begin(), pathStr.end(), '\\', '/');
#endif
return pathStr;
}

private:
static void initializeConnection(TestQueryConfig* config, main::Connection& conn);
};
Expand Down
3 changes: 1 addition & 2 deletions test/include/test_runner/test_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ class TestParser {
const std::string& testCaseName);
TestStatement* addNewStatement(std::string& name);

const std::string exportDBPath = TestHelper::appendKuzuRootPath(
TestHelper::TMP_TEST_DIR + std::string("export_db") + TestHelper::getMillisecondsSuffix());
const std::string exportDBPath = TestHelper::getTempDir("export_db");
// Any value here will be replaced inside the .test files
// in queries/statements and expected error message.
// Example: ${KUZU_ROOT_DIRECTORY} will be replaced by
Expand Down
22 changes: 2 additions & 20 deletions test/runner/cleanup_test.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
#include "graph_test/graph_test.h"
#include "test_helper/test_helper.h"

using namespace kuzu::testing;
using namespace kuzu::common;

void deleteMatchingDir(const std::string& dirPath, const std::string& match) {
for (const auto& entry : std::filesystem::directory_iterator(dirPath)) {
if (entry.path().filename().string().find(match) != std::string::npos) {
std::filesystem::remove_all(entry.path().string());
}
}
}

int main(int argc, char** argv) {
std::vector<std::string> tempDirs = {TestHelper::PARQUET_TEMP_DATASET_PATH,
TestHelper::TMP_TEST_DIR};
if (argc > 1 && std::string(argv[1]) == "--gtest_list_tests") {
for (const auto& tempDir : tempDirs) {
// path = test/unittest_temp_
std::filesystem::path path = tempDir;
// dirToCheck = test
std::string dirToCheck = path.parent_path().string();
// dirPatternToRemove = unittest_temp_
std::string dirPatternToRemove = path.filename().string();
deleteMatchingDir(TestHelper::appendKuzuRootPath(dirToCheck), dirPatternToRemove);
}
std::filesystem::remove_all(TestHelper::getTempDir());
}
return 0;
}
4 changes: 1 addition & 3 deletions test/runner/e2e_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ class EndToEndTest : public DBTest {
std::string generateParquetTempDatasetPath() {
std::string datasetName = dataset;
std::replace(datasetName.begin(), datasetName.end(), '/', '_');
return TestHelper::appendKuzuRootPath(TestHelper::PARQUET_TEMP_DATASET_PATH + datasetName +
"_" + getTestGroupAndName() + "_" +
TestHelper::getMillisecondsSuffix());
return TestHelper::getTempDir(datasetName + "_parquet_" + getTestGroupAndName());
}
};

Expand Down
8 changes: 2 additions & 6 deletions test/test_runner/csv_to_parquet_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ void CSVToParquetConverter::createCopyFile() {
throw TestException(
stringFormat("Error opening file: {}, errno: {}.", parquetCopyFile, errno));
}
std::string kuzuRootPath = KUZU_ROOT_DIRECTORY + std::string("/");
for (auto table : tables) {
auto cmd = stringFormat("COPY {} FROM \"{}\";", table->name,
table->parquetFilePath.substr(kuzuRootPath.length()));
auto cmd = stringFormat("COPY {} FROM \"{}\";", table->name, table->parquetFilePath);
outfile << cmd << '\n';
}
}
Expand Down Expand Up @@ -168,9 +166,7 @@ void CSVToParquetConverter::convertCSVDatasetToParquet() {
createCopyFile();

systemConfig = std::make_unique<main::SystemConfig>(bufferPoolSize);
std::string tempDatabasePath = TestHelper::appendKuzuRootPath(
std::string(TestHelper::TMP_TEST_DIR) + "csv_to_parquet_converter_" +
TestHelper::getMillisecondsSuffix());
std::string tempDatabasePath = TestHelper::getTempDir("csv_to_parquet_converter");
tempDb = std::make_unique<main::Database>(tempDatabasePath, *systemConfig);
tempConn = std::make_unique<main::Connection>(tempDb.get());

Expand Down
Loading