Skip to content

Commit

Permalink
[chore][store] Unify all unit test to one execute file.
Browse files Browse the repository at this point in the history
  • Loading branch information
rock-git authored and ketor committed Nov 27, 2023
1 parent 2b1fc2f commit 319e3e1
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 45 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ project(dingo-store C CXX)

option(EXAMPLE_LINK_SO "Whether examples are linked dynamically" OFF)
option(LINK_TCMALLOC "Link tcmalloc if possible" OFF)
option(BUILD_UNIT_TESTS "Build unit test" OFF)
option(BUILD_UNIT_TESTS "Build unit test" ON)
option(DINGO_BUILD_STATIC "Link libraries statically to generate the DingoDB binary" ON)
option(ENABLE_FAILPOINT "Enable failpoint" OFF)
option(WITH_DISKANN "Build with diskann index" OFF)
Expand Down
35 changes: 18 additions & 17 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
enable_testing()

SET(UNIT_TEST_BIN "dingodb_unit_test")

file(GLOB TEST_SRCS "test_*.cc")
foreach(TEST_SRC ${TEST_SRCS})
message(STATUS "TEST_SRC: ${TEST_SRC}")
get_filename_component(TEST_WE ${TEST_SRC} NAME_WE)
add_executable(${TEST_WE}
${TEST_SRC}
$<TARGET_OBJECTS:DINGODB_OBJS>
$<TARGET_OBJECTS:PROTO_OBJS>
)
add_dependencies(${TEST_WE} ${DEPEND_LIBS})
target_link_libraries(${TEST_WE}
"-Xlinker \"-(\""
${GTEST_MAIN_LIBRARIES}
${GTEST_LIBRARIES}
${DYNAMIC_LIB}
"-Xlinker \"-)\""
)
endforeach()

add_executable(${UNIT_TEST_BIN}
main.cc
${TEST_SRCS}
$<TARGET_OBJECTS:DINGODB_OBJS>
$<TARGET_OBJECTS:PROTO_OBJS>
)

add_dependencies(${UNIT_TEST_BIN} ${DEPEND_LIBS})

target_link_libraries(${UNIT_TEST_BIN}
"-Xlinker \"-(\""
${GTEST_LIBRARIES}
${DYNAMIC_LIB}
"-Xlinker \"-)\""
)

add_subdirectory(sdk)
21 changes: 21 additions & 0 deletions test/main.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2023 dingodb.com, Inc. All Rights Reserved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <gtest/gtest.h>

int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}
4 changes: 2 additions & 2 deletions test/test_coprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const std::string kYamlConfigContent =
" path: " +
kStorePath + "\n";

std::string StrToHex(std::string str, std::string separator = "") {
static std::string StrToHex(std::string str, std::string separator = "") {
const std::string hex = "0123456789ABCDEF";
std::stringstream ss;

Expand All @@ -90,7 +90,7 @@ std::string StrToHex(std::string str, std::string separator = "") {
}

// rand string
std::string GenRandomString(int len) {
static std::string GenRandomString(int len) {
std::string result;
int alphabet_len = sizeof(kAlphabet);

Expand Down
10 changes: 5 additions & 5 deletions test/test_raft_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ std::string GetRaftInitConf(const std::vector<std::string>& raft_addrs) {
return s;
}

dingodb::store::RegionPtr BuildRegion(int64_t region_id, const std::string& raft_group_name,
std::vector<std::string>& raft_addrs) {
static dingodb::store::RegionPtr BuildRegion(int64_t region_id, const std::string& raft_group_name,
std::vector<std::string>& raft_addrs) {
dingodb::pb::common::RegionDefinition region_definition;
region_definition.set_id(region_id);
region_definition.set_name(raft_group_name);
Expand Down Expand Up @@ -133,8 +133,7 @@ std::shared_ptr<dingodb::RaftNode> LaunchRaftNode(std::shared_ptr<dingodb::Confi
const dingodb::pb::common::Peer& peer, std::string init_conf) {
// build state machine
auto raft_meta = dingodb::StoreRaftMeta::NewRaftMeta(region->Id());
auto state_machine =
std::make_shared<dingodb::StoreStateMachine>(nullptr, region, raft_meta, nullptr, nullptr);
auto state_machine = std::make_shared<dingodb::StoreStateMachine>(nullptr, region, raft_meta, nullptr, nullptr);
if (!state_machine->Init()) {
std::cout << "Init state machine failed";
return nullptr;
Expand All @@ -149,7 +148,8 @@ std::shared_ptr<dingodb::RaftNode> LaunchRaftNode(std::shared_ptr<dingodb::Confi
auto node = std::make_shared<dingodb::RaftNode>(
node_id, region->Name(), braft::PeerId(FormatLocation(peer.raft_location())), state_machine, log_storage);

if (node->Init(region, init_conf, config->GetString("raft.path"), config->GetInt("raft.election_timeout_s") * 1000)) {
if (node->Init(region, init_conf, config->GetString("raft.path"), config->GetInt("raft.election_timeout_s") * 1000) !=
0) {
node->Destroy();
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_raft_snapshot_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const char kAlphabet[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
's', 't', 'o', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

// rand string
std::string GenRandomString(int len) {
static std::string GenRandomString(int len) {
std::string result;
int alphabet_len = sizeof(kAlphabet);

Expand Down
2 changes: 1 addition & 1 deletion test/test_rocks_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const char kAlphabet[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
's', 't', 'o', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

// rand string
std::string GenRandomString(int len) {
static std::string GenRandomString(int len) {
std::string result;
int alphabet_len = sizeof(kAlphabet);

Expand Down
2 changes: 1 addition & 1 deletion test/test_scan_with_coprocessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const std::string kYamlConfigContent =
" path: " +
kStorePath + "\n";

std::string StrToHex(std::string str, std::string separator = "") {
static std::string StrToHex(std::string str, std::string separator = "") {
const std::string hex = "0123456789ABCDEF";
std::stringstream ss;

Expand Down
2 changes: 1 addition & 1 deletion test/test_split_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const char kAlphabet[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
// ================== Helper function ==================

// rand string
std::string GenRandomString(int len) {
static std::string GenRandomString(int len) {
std::string result;
int alphabet_len = sizeof(kAlphabet);

Expand Down
6 changes: 3 additions & 3 deletions test/test_store_metrics_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const char kAlphabet[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
's', 't', 'o', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};

// rand string
std::string GenRandomString(int len) {
static std::string GenRandomString(int len) {
std::string result;
int alphabet_len = sizeof(kAlphabet);

Expand Down Expand Up @@ -99,8 +99,8 @@ class StoreRegionMetricsTest : public testing::Test {

std::shared_ptr<dingodb::RawRocksEngine> StoreRegionMetricsTest::engine = nullptr;

dingodb::store::RegionPtr BuildRegion(int64_t region_id, const std::string& raft_group_name,
std::vector<std::string>& raft_addrs) {
static dingodb::store::RegionPtr BuildRegion(int64_t region_id, const std::string& raft_group_name,
std::vector<std::string>& raft_addrs) {
dingodb::pb::common::RegionDefinition region_definition;
region_definition.set_id(region_id);
region_definition.set_name(raft_group_name);
Expand Down
10 changes: 5 additions & 5 deletions test/test_vector_index_flat_search_limit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

namespace dingodb {

class VectorIndexFlatSearchParamTest : public testing::Test {
class VectorIndexFlatSearchParamLimitTest : public testing::Test {
protected:
static void SetUpTestSuite() {}

Expand Down Expand Up @@ -72,7 +72,7 @@ class VectorIndexFlatSearchParamTest : public testing::Test {
inline static int search_topk = 1;
};

TEST_F(VectorIndexFlatSearchParamTest, Create) {
TEST_F(VectorIndexFlatSearchParamLimitTest, Create) {
static const pb::common::Range kRange;
static pb::common::RegionEpoch kEpoch; // NOLINT
kEpoch.set_conf_version(1);
Expand Down Expand Up @@ -113,7 +113,7 @@ TEST_F(VectorIndexFlatSearchParamTest, Create) {
}
}

TEST_F(VectorIndexFlatSearchParamTest, Search) {
TEST_F(VectorIndexFlatSearchParamLimitTest, Search) {
butil::Status ok;

auto lambda_random_function = []() {
Expand Down Expand Up @@ -259,7 +259,7 @@ TEST_F(VectorIndexFlatSearchParamTest, Search) {
}
}

TEST_F(VectorIndexFlatSearchParamTest, Upsert) {
TEST_F(VectorIndexFlatSearchParamLimitTest, Upsert) {
butil::Status ok;

// create random data
Expand Down Expand Up @@ -318,7 +318,7 @@ TEST_F(VectorIndexFlatSearchParamTest, Upsert) {
}
}

TEST_F(VectorIndexFlatSearchParamTest, SearchAfterInsert) {
TEST_F(VectorIndexFlatSearchParamLimitTest, SearchAfterInsert) {
butil::Status ok;

auto lambda_random_function = []() {
Expand Down
6 changes: 3 additions & 3 deletions test/test_vector_index_memory_flat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

namespace dingodb {

class VectorIndexMemoryTest : public testing::Test {
class VectorIndexMemoryFlatTest : public testing::Test {
protected:
static void SetUpTestSuite() {}

Expand All @@ -54,7 +54,7 @@ class VectorIndexMemoryTest : public testing::Test {
inline static int step_count = 1000;
};

TEST_F(VectorIndexMemoryTest, Create) {
TEST_F(VectorIndexMemoryFlatTest, Create) {
static const pb::common::Range kRange;
std::cout << "pid : " << getpid() << '\n';
static pb::common::RegionEpoch kEpoch;
Expand All @@ -73,7 +73,7 @@ TEST_F(VectorIndexMemoryTest, Create) {
}
}

TEST_F(VectorIndexMemoryTest, Add) {
TEST_F(VectorIndexMemoryFlatTest, Add) {
butil::Status ok;

// create random data
Expand Down
6 changes: 3 additions & 3 deletions test/test_vector_index_memory_hnsw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

namespace dingodb {

class VectorIndexMemoryTest : public testing::Test {
class VectorIndexMemoryHnswTest : public testing::Test {
protected:
static void SetUpTestSuite() {}

Expand All @@ -55,7 +55,7 @@ class VectorIndexMemoryTest : public testing::Test {
inline static int step_count = 1000;
};

TEST_F(VectorIndexMemoryTest, Create) {
TEST_F(VectorIndexMemoryHnswTest, Create) {
static const pb::common::Range kRange;
static pb::common::RegionEpoch kEpoch;
kEpoch.set_conf_version(1);
Expand All @@ -79,7 +79,7 @@ TEST_F(VectorIndexMemoryTest, Create) {
}
}

TEST_F(VectorIndexMemoryTest, Add) {
TEST_F(VectorIndexMemoryHnswTest, Add) {
butil::Status ok;

// create random data
Expand Down
4 changes: 2 additions & 2 deletions test/test_vector_index_raw_ivf_pq_boundary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

namespace dingodb {

class VectorIndexRawIvfPqTest : public testing::Test {
class VectorIndexRawIvfPqBoundaryTest : public testing::Test {
protected:
static void SetUpTestSuite() {}

Expand Down Expand Up @@ -113,7 +113,7 @@ class VectorIndexRawIvfPqTest : public testing::Test {
inline static int32_t start_id = 1000;
};

TEST_F(VectorIndexRawIvfPqTest, Create) {
TEST_F(VectorIndexRawIvfPqBoundaryTest, Create) {
butil::Status ok;
static pb::common::RegionEpoch kEpoch; // NOLINT
kEpoch.set_conf_version(1);
Expand Down

0 comments on commit 319e3e1

Please sign in to comment.