Skip to content

Commit

Permalink
use one EndToEndTest class
Browse files Browse the repository at this point in the history
  • Loading branch information
hououou committed Sep 14, 2023
1 parent 417e86d commit 5c35970
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 32 deletions.
27 changes: 25 additions & 2 deletions test/graph_test/graph_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ void TestHelper::executeScript(const std::string& cypherScript, Connection& conn
}
}
}
void BaseGraphTest::createDB(uint64_t checkpointWaitTimeout) {
if (database != nullptr) {
database.reset();
}
database = std::make_unique<main::Database>(databasePath, *systemConfig);
spdlog::set_level(spdlog::level::info);
}

void BaseGraphTest::createConns(const std::set<std::string>& connNames) {
if(connNames.size()==0){//impart a default connName
conn = std::make_unique<main::Connection>(database.get());
}else{
for(auto connName: connNames){
connMap[connName] = std::make_unique<main::Connection>(database.get());
}
}
}

void BaseGraphTest::createDBAndConn() {
if (database != nullptr) {
Expand All @@ -169,8 +186,14 @@ void BaseGraphTest::createDBAndConn() {
}

void BaseGraphTest::initGraph() {
TestHelper::executeScript(getInputDir() + TestHelper::SCHEMA_FILE_NAME, *conn);
TestHelper::executeScript(getInputDir() + TestHelper::COPY_FILE_NAME, *conn);
if(conn){//normal conn
TestHelper::executeScript(getInputDir() + TestHelper::SCHEMA_FILE_NAME, *conn);
TestHelper::executeScript(getInputDir() + TestHelper::COPY_FILE_NAME, *conn);
}else{
//choose a conn from connMap
TestHelper::executeScript(getInputDir() + TestHelper::SCHEMA_FILE_NAME, *(connMap.begin()->second));
TestHelper::executeScript(getInputDir() + TestHelper::COPY_FILE_NAME, *(connMap.begin()->second));
}
}

void BaseGraphTest::commitOrRollbackConnection(
Expand Down
17 changes: 15 additions & 2 deletions test/include/graph_test/graph_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class BaseGraphTest : public Test {

void createDBAndConn();

// multiple conns test
void createDB(uint64_t checkpointWaitTimeout);
void createConns(const std::set<std::string>& connNames);

void initGraph();

void commitOrRollbackConnection(bool isCommit, TransactionTestType transactionTestType) const;
Expand Down Expand Up @@ -140,7 +144,10 @@ class BaseGraphTest : public Test {
std::string databasePath;
std::unique_ptr<main::SystemConfig> systemConfig;
std::unique_ptr<main::Database> database;
//for normal conn; if it is null, respects multiple conns, need to use connMap
std::unique_ptr<main::Connection> conn;
// for multiple conns
std::unordered_map<std::string, std::unique_ptr<main::Connection>> connMap;
};

// This class starts database without initializing graph.
Expand All @@ -158,9 +165,15 @@ class DBTest : public BaseGraphTest {
}

inline void runTest(const std::vector<std::unique_ptr<TestStatement>>& statements) {
TestRunner::runTest(statements, *conn, databasePath);
for (auto& statement : statements) {
auto conn_name = *statement->conn_name;
if(conn){
TestRunner::runTest(statement.get(), *conn, databasePath);
}else{
TestRunner::runTest(statement.get(), *connMap[conn_name], databasePath);
}
}
}
};

} // namespace testing
} // namespace kuzu
10 changes: 9 additions & 1 deletion test/include/test_runner/test_group.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <set>
#include "main/kuzu.h"
#include <optional>

namespace kuzu {
namespace testing {
Expand All @@ -18,6 +19,8 @@ struct TestStatement {
bool enumerate = false;
bool checkOutputOrder = false;
std::string expectedTuplesCSVFile;
// for multiple conns
std::optional<std::string> conn_name; // default conntion name conn0
};

// Test group is a collection of test cases in a single file.
Expand All @@ -31,6 +34,11 @@ struct TestGroup {
std::unordered_map<std::string, std::vector<std::unique_ptr<TestStatement>>>
testCasesStatementBlocks;
uint64_t bufferPoolSize = common::BufferPoolConstants::DEFAULT_BUFFER_POOL_SIZE_FOR_TESTING;
// for multiple connections
uint64_t checkpointWaitTimeout =
common::DEFAULT_CHECKPOINT_WAIT_TIMEOUT_FOR_TRANSACTIONS_TO_LEAVE_IN_MICROS;;
bool multipleConns = false;
std::unordered_map<std::string, std::set<std::string>> testCasesConnNames;

enum class DatasetType { CSV, PARQUET, NPY, CSV_TO_PARQUET };
DatasetType datasetType;
Expand Down
12 changes: 9 additions & 3 deletions test/include/test_runner/test_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ enum class TokenType {
ROLLBACK,
SEPARATOR,
STATEMENT,
_SKIP_LINE
_SKIP_LINE,

CHECKPOINT_WAIT_TIMEOUT,
CREATE_CONNECTION
};

const std::unordered_map<std::string, TokenType> tokenMap = {{"-GROUP", TokenType::GROUP},
Expand All @@ -47,6 +50,8 @@ const std::unordered_map<std::string, TokenType> tokenMap = {{"-GROUP", TokenTyp
{"-DEFINE", TokenType::DEFINE}, {"-STATEMENT", TokenType::STATEMENT},
{"-INSERT_STATEMENT_BLOCK", TokenType::INSERT_STATEMENT_BLOCK},
{"-ROLLBACK", TokenType::ROLLBACK}, {"-BUFFER_POOL_SIZE", TokenType::BUFFER_POOL_SIZE},
{"-CHECKPOINT_WAIT_TIMEOUT", TokenType::CHECKPOINT_WAIT_TIMEOUT},
{"-CREATE_CONNECTION", TokenType::CREATE_CONNECTION},
{"]", TokenType::END_OF_STATEMENT_BLOCK}, {"----", TokenType::RESULT},
{"--", TokenType::SEPARATOR}, {"#", TokenType::EMPTY}};

Expand All @@ -59,7 +64,7 @@ class LogicToken {
class TestParser {
public:
explicit TestParser(const std::string& path)
: testGroup{std::make_unique<TestGroup>()}, path{path} {}
: testGroup{std::make_unique<TestGroup>()},path{path} {}
std::unique_ptr<TestGroup> parseTestFile();

private:
Expand All @@ -84,6 +89,7 @@ class TestParser {
void extractDataset();
void addStatementBlock(const std::string& blockName, const std::string& testGroupName);
void replaceVariables(std::string& str);
bool extractConnName(std::string& query, TestStatement* statement);

inline bool endOfFile() { return fileStream.eof(); }
inline void setCursorToPreviousLine() { fileStream.seekg(previousFilePosition); }
Expand All @@ -109,7 +115,7 @@ class TestParser {
});
}

TestStatement* extractStatement(TestStatement* currentStatement);
TestStatement* extractStatement(TestStatement* currentStatement,const std::string& testCaseName);
TestStatement* addNewStatement(std::string& name);

// Any value here will be replaced inside the .test files
Expand Down
4 changes: 2 additions & 2 deletions test/include/test_runner/test_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace testing {

class TestRunner {
public:
static void runTest(const std::vector<std::unique_ptr<TestStatement>>& statements,
main::Connection& conn, std::string& databasePath);
static void runTest(TestStatement* statement, main::Connection& conn,
std::string& databasePath);

static std::unique_ptr<planner::LogicalPlan> getLogicalPlan(
const std::string& query, main::Connection& conn);
Expand Down
26 changes: 16 additions & 10 deletions test/runner/e2e_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ using namespace kuzu::common;
class EndToEndTest : public DBTest {
public:
explicit EndToEndTest(TestGroup::DatasetType datasetType, std::string dataset,
uint64_t bufferPoolSize, std::vector<std::unique_ptr<TestStatement>> testStatements)
uint64_t bufferPoolSize, uint64_t checkpointWaitTimeout,const std::set<std::string>& connNames,
std::vector<std::unique_ptr<TestStatement>> testStatements)
: datasetType{datasetType}, dataset{std::move(dataset)}, bufferPoolSize{bufferPoolSize},
testStatements{std::move(testStatements)} {}
checkpointWaitTimeout{checkpointWaitTimeout}, connNames{connNames},testStatements{std::move(testStatements)} {}

void SetUp() override {
setUpDataset();
BaseGraphTest::SetUp();
systemConfig->bufferPoolSize = bufferPoolSize;
createDBAndConn();
createDB(checkpointWaitTimeout);
createConns(connNames);
if (dataset != "empty") {
initGraph();
}
Expand Down Expand Up @@ -46,7 +48,9 @@ class EndToEndTest : public DBTest {
std::string dataset;
std::string parquetTempDatasetPath;
uint64_t bufferPoolSize;
uint64_t checkpointWaitTimeout;
std::vector<std::unique_ptr<TestStatement>> testStatements;
std::set<std::string> connNames;

std::string generateParquetTempDatasetPath() {
return TestHelper::appendKuzuRootPath(
Expand All @@ -64,6 +68,7 @@ void parseAndRegisterTestGroup(const std::string& path, bool generateTestList =
auto dataset = testGroup->dataset;
auto testCases = std::move(testGroup->testCases);
auto bufferPoolSize = testGroup->bufferPoolSize;
auto checkpointWaitTimeout = testGroup->checkpointWaitTimeout;
for (auto& [testCaseName, testStatements] : testCases) {
if (generateTestList) {
std::ofstream testList(TestHelper::getTestListFile(), std::ios_base::app);
Expand All @@ -72,13 +77,14 @@ void parseAndRegisterTestGroup(const std::string& path, bool generateTestList =
if (empty(testCaseName)) {
throw TestException("Missing test case name (-CASE) [" + path + "].");
}
testing::RegisterTest(testGroup->group.c_str(), testCaseName.c_str(), nullptr, nullptr,
__FILE__, __LINE__,
[datasetType, dataset, bufferPoolSize,
testStatements = std::move(testStatements)]() mutable -> DBTest* {
return new EndToEndTest(
datasetType, dataset, bufferPoolSize, std::move(testStatements));
});
auto connNames=testGroup->testCasesConnNames[testCaseName];
testing::RegisterTest(testGroup->group.c_str(), testCaseName.c_str(), nullptr,
nullptr, __FILE__, __LINE__,
[datasetType, dataset, bufferPoolSize, checkpointWaitTimeout,connNames,
testStatements = std::move(testStatements)]() mutable -> DBTest* {
return new EndToEndTest(datasetType, dataset, bufferPoolSize,
checkpointWaitTimeout, connNames,std::move(testStatements));
});
}
} else {
throw TestException("Invalid test file [" + path + "].");
Expand Down
73 changes: 73 additions & 0 deletions test/test_files/transaction/set_transaction.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
-GROUP Set_Transaction
-DATASET CSV tinysnb

--


#SingleTransactionReadWriteToFixedLengthStructuredNodePropertyNonNullTest
-CASE NonNullTest
-LOG Single Transaction Read Write To Fixed Length Structured Node Property NonNull Test
-STATEMENT BEGIN WRITE TRANSACTION
-STATEMENT MATCH (a:person) WHERE a.ID=0 RETURN a.age;
---- 1
35

-STATEMENT MATCH (a:person) WHERE a.ID = 0 SET a.age = 70;
---- ok

-STATEMENT MATCH (a:person) WHERE a.ID=0 RETURN a.age;
---- 1
70

#NullTest
-CASE NullTest
-LOG Single Transaction Read Write To Fixed Length Structured Node Property Null Test
-STATEMENT BEGIN WRITE TRANSACTION
-STATEMENT MATCH (a:person) WHERE a.ID=0 RETURN a.age;
---- 1
35

-STATEMENT MATCH (a:person) WHERE a.ID = 0 SET a.age = null;
---- ok

-STATEMENT MATCH (a:person) WHERE a.ID=0 RETURN a.age;
---- 1

#Timeout
-CASE TimeoutErrorTest
-LOG Open Read Only Transaction Triggers Timeout Error For Write Transaction
-CHECKPOINT_WAIT_TIMEOUT 10000
-CREATE_CONNECTION conn1
-STATEMENT [conn1] BEGIN READ TRANSACTION;
-CREATE_CONNECTION conn2
-STATEMENT [conn2] BEGIN WRITE TRANSACTION
-STATEMENT [conn2] MATCH (a:person) WHERE a.ID=0 set a.age=70;
---- ok
-STATEMENT [conn2] COMMIT
---- ok
-STATEMENT [conn1] MATCH (a:person) WHERE a.ID=0 RETURN a.age;
---- 1
70


#RollbackTest
-CASE RollbackTest
-LOG Set Node Long String Prop Rollback Test
-STATEMENT BEGIN WRITE TRANSACTION;
---- ok
-STATEMENT MATCH (a:person) WHERE a.ID=0 SET a.fName='abcdefghijklmnopqrstuvwxyz'
---- ok
-STATEMENT ROLLBACK
---- ok
-STATEMENT MATCH (a:person) WHERE a.ID=0 RETURN a.fName;
---- 1
Alice

#VeryLongStringErrorsTest
-CASE VeryLongStringErrorsTest
-LOG Set Very Long String Errors Test
-STATEMENT BEGIN WRITE TRANSACTION;
---- ok
-DEFINE test_long_string REPEAT 4096 "a"
-STATEMENT MATCH (a:person) WHERE a.ID=0 SET a.fName='${test_long_string}';
---- ok
Loading

0 comments on commit 5c35970

Please sign in to comment.