Skip to content

Commit

Permalink
Move tests into system temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwinger committed Apr 16, 2024
1 parent b24d41b commit d038898
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 36 deletions.
3 changes: 1 addition & 2 deletions test/include/graph_test/base_graph_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ class BaseGraphTest : public Test {

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

public:
Expand Down
20 changes: 17 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,25 @@ 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::filesystem::path getTempDir(const std::string& name) {
auto path = getTempDir() / (name + TestHelper::getMillisecondsSuffix());
std::filesystem::create_directories(path);
return path;
}

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").string();
// 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;
}
8 changes: 5 additions & 3 deletions test/runner/e2e_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class EndToEndTest : public DBTest {
if (datasetType == TestGroup::DatasetType::CSV_TO_PARQUET) {
auto csvDatasetPath = TestHelper::appendKuzuRootPath("dataset/" + dataset);
parquetTempDatasetPath = generateParquetTempDatasetPath();
#ifdef _WIN32
// kuzu still doesn't support backslashes in paths on windows
std::replace(parquetTempDatasetPath.begin(), parquetTempDatasetPath.end(), '\\', '/');
#endif
CSVToParquetConverter converter(csvDatasetPath, parquetTempDatasetPath, bufferPoolSize);
converter.convertCSVDatasetToParquet();
dataset = parquetTempDatasetPath;
Expand Down Expand Up @@ -64,9 +68,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()).string();
}
};

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").string();
tempDb = std::make_unique<main::Database>(tempDatabasePath, *systemConfig);
tempConn = std::make_unique<main::Connection>(tempDb.get());

Expand Down

0 comments on commit d038898

Please sign in to comment.