From 2deba2dcb99c36e7ae00711a84760cd9a841f1b2 Mon Sep 17 00:00:00 2001 From: "yudong.cai" Date: Wed, 6 Nov 2019 16:22:38 +0800 Subject: [PATCH] #208 optimize unittest to support run single test more easily --- CHANGELOG.md | 1 + core/src/server/Config.cpp | 14 ++++++++++---- core/src/server/Config.h | 3 ++- core/unittest/db/CMakeLists.txt | 12 ++++++++++-- core/unittest/db/utils.cpp | 4 ++-- core/unittest/metrics/CMakeLists.txt | 6 +++++- core/unittest/scheduler/CMakeLists.txt | 12 +++++++++++- .../scheduler/{task_test.cpp => test_task.cpp} | 0 core/unittest/server/CMakeLists.txt | 7 ++++++- core/unittest/wrapper/CMakeLists.txt | 6 +++++- core/unittest/wrapper/utils.cpp | 4 ++-- 11 files changed, 54 insertions(+), 15 deletions(-) rename core/unittest/scheduler/{task_test.cpp => test_task.cpp} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88b2a69e..d49922b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Please mark all change in change log and use the ticket from JIRA. ## Improvement - \#207 - Add more unittest for config set/get +- \#208 - optimize unittest to support run single test more easily ## Task diff --git a/core/src/server/Config.cpp b/core/src/server/Config.cpp index 20bcb937..ccc518ca 100644 --- a/core/src/server/Config.cpp +++ b/core/src/server/Config.cpp @@ -795,11 +795,16 @@ Config::GetConfigStr(const std::string& parent_key, const std::string& child_key } std::string -Config::GetConfigSequenceStr(const std::string& parent_key, const std::string& child_key, const std::string& delim) { +Config::GetConfigSequenceStr(const std::string& parent_key, const std::string& child_key, const std::string& delim, + const std::string& default_value) { std::string value; if (!GetConfigValueInMem(parent_key, child_key, value).ok()) { std::vector sequence = GetConfigNode(parent_key).GetSequence(child_key); - server::StringHelpFunctions::MergeStringWithDelimeter(sequence, delim, value); + if (sequence.empty()) { + value = default_value; + } else { + server::StringHelpFunctions::MergeStringWithDelimeter(sequence, delim, value); + } SetConfigValueInMem(parent_key, child_key, value); } return value; @@ -1028,8 +1033,9 @@ Config::GetResourceConfigMode(std::string& value) { Status Config::GetResourceConfigSearchResources(std::vector& value) { - std::string str = GetConfigSequenceStr(CONFIG_RESOURCE, CONFIG_RESOURCE_SEARCH_RESOURCES, - CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER); + std::string str = + GetConfigSequenceStr(CONFIG_RESOURCE, CONFIG_RESOURCE_SEARCH_RESOURCES, + CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, CONFIG_RESOURCE_SEARCH_RESOURCES_DEFAULT); server::StringHelpFunctions::SplitStringByDelimeter(str, CONFIG_RESOURCE_SEARCH_RESOURCES_DELIMITER, value); return CheckResourceConfigSearchResources(value); } diff --git a/core/src/server/Config.h b/core/src/server/Config.h index df43f040..e466b70a 100644 --- a/core/src/server/Config.h +++ b/core/src/server/Config.h @@ -186,7 +186,8 @@ class Config { std::string GetConfigStr(const std::string& parent_key, const std::string& child_key, const std::string& default_value = ""); std::string - GetConfigSequenceStr(const std::string& parent_key, const std::string& child_key, const std::string& delim); + GetConfigSequenceStr(const std::string& parent_key, const std::string& child_key, const std::string& delim = ",", + const std::string& default_value = ""); public: /* server config */ diff --git a/core/unittest/db/CMakeLists.txt b/core/unittest/db/CMakeLists.txt index 3954dd86..92ddc910 100644 --- a/core/unittest/db/CMakeLists.txt +++ b/core/unittest/db/CMakeLists.txt @@ -17,8 +17,16 @@ # under the License. #------------------------------------------------------------------------------- - -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} test_files) +set(test_files + ${CMAKE_CURRENT_SOURCE_DIR}/test_db.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_db_mysql.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_engine.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_mem.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_meta.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_meta_mysql.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_misc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_search.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp) cuda_add_executable(test_db ${common_files} diff --git a/core/unittest/db/utils.cpp b/core/unittest/db/utils.cpp index 16e19507..9dce7797 100644 --- a/core/unittest/db/utils.cpp +++ b/core/unittest/db/utils.cpp @@ -60,8 +60,8 @@ static const char " port: 8080 # port prometheus used to fetch metrics\n" "\n" "cache_config:\n" - " cpu_mem_capacity: 16 # GB, CPU memory used for cache\n" - " cpu_mem_threshold: 0.85 # percentage of data kept when cache cleanup triggered\n" + " cpu_cache_capacity: 16 # GB, CPU memory used for cache\n" + " cpu_cache_threshold: 0.85 # percentage of data kept when cache cleanup triggered\n" " cache_insert_data: false # whether load inserted data into cache\n" "\n" "engine_config:\n" diff --git a/core/unittest/metrics/CMakeLists.txt b/core/unittest/metrics/CMakeLists.txt index eba8146b..ad9d4e39 100644 --- a/core/unittest/metrics/CMakeLists.txt +++ b/core/unittest/metrics/CMakeLists.txt @@ -17,7 +17,11 @@ # under the License. #------------------------------------------------------------------------------- -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} test_files) +set(test_files + ${CMAKE_CURRENT_SOURCE_DIR}/test_metricbase.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_metrics.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_prometheus.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp) add_executable(test_metrics ${common_files} diff --git a/core/unittest/scheduler/CMakeLists.txt b/core/unittest/scheduler/CMakeLists.txt index 087f93f0..6a48d401 100644 --- a/core/unittest/scheduler/CMakeLists.txt +++ b/core/unittest/scheduler/CMakeLists.txt @@ -17,7 +17,17 @@ # under the License. #------------------------------------------------------------------------------- -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} test_files) +set(test_files + ${CMAKE_CURRENT_SOURCE_DIR}/test_algorithm.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_event.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_node.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_normal.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_resource.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_resource_factory.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_resource_mgr.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_scheduler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_task.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_tasktable.cpp) cuda_add_executable(test_scheduler ${common_files} diff --git a/core/unittest/scheduler/task_test.cpp b/core/unittest/scheduler/test_task.cpp similarity index 100% rename from core/unittest/scheduler/task_test.cpp rename to core/unittest/scheduler/test_task.cpp diff --git a/core/unittest/server/CMakeLists.txt b/core/unittest/server/CMakeLists.txt index 1f89de8d..742b1fad 100644 --- a/core/unittest/server/CMakeLists.txt +++ b/core/unittest/server/CMakeLists.txt @@ -17,7 +17,12 @@ # under the License. #------------------------------------------------------------------------------- -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} test_files) +set(test_files + ${CMAKE_CURRENT_SOURCE_DIR}/test_cache.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_config.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_rpc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_util.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp) include_directories("${CUDA_TOOLKIT_ROOT_DIR}/include") link_directories("${CUDA_TOOLKIT_ROOT_DIR}/lib64") diff --git a/core/unittest/wrapper/CMakeLists.txt b/core/unittest/wrapper/CMakeLists.txt index ef145a9f..3f2be064 100644 --- a/core/unittest/wrapper/CMakeLists.txt +++ b/core/unittest/wrapper/CMakeLists.txt @@ -17,7 +17,11 @@ # under the License. #------------------------------------------------------------------------------- -aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} test_files) +set(test_files + ${CMAKE_CURRENT_SOURCE_DIR}/test_hybrid_index.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_knowhere.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_wrapper.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/utils.cpp) set(wrapper_files ${MILVUS_ENGINE_SRC}/wrapper/DataTransfer.cpp diff --git a/core/unittest/wrapper/utils.cpp b/core/unittest/wrapper/utils.cpp index b397a35d..e17077ae 100644 --- a/core/unittest/wrapper/utils.cpp +++ b/core/unittest/wrapper/utils.cpp @@ -50,8 +50,8 @@ static const char " port: 8080 # port prometheus used to fetch metrics\n" "\n" "cache_config:\n" - " cpu_mem_capacity: 16 # GB, CPU memory used for cache\n" - " cpu_mem_threshold: 0.85 # percentage of data kept when cache cleanup triggered\n" + " cpu_cache_capacity: 16 # GB, CPU memory used for cache\n" + " cpu_cache_threshold: 0.85 # percentage of data kept when cache cleanup triggered\n" " cache_insert_data: false # whether load inserted data into cache\n" "\n" "engine_config:\n" -- GitLab