From 7965b4c70326157f5e74d8b88f2601cdd9db9f29 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 26 Aug 2021 17:03:42 +0800 Subject: [PATCH] [TD-5992] add test case --- src/client/src/tscSystem.c | 2 +- src/client/tests/setConfigTest.cpp | 26 ++++++++++++++++++++------ src/util/inc/tconfig.h | 2 +- src/util/src/tconfig.c | 5 +++-- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 2d36a4bef4..f23ec1548c 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -454,7 +454,7 @@ static int taos_set_config_imp(const char *config){ int size = cJSON_GetArraySize(root); for(int i = 0; i < size; i++){ cJSON *item = cJSON_GetArrayItem(root, i); - if(item && !taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION)){ + if(item && !taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION, TSDB_CFG_CTYPE_B_CLIENT)){ ret = -2; } } diff --git a/src/client/tests/setConfigTest.cpp b/src/client/tests/setConfigTest.cpp index 63cda16bb5..e7c34ed8f1 100644 --- a/src/client/tests/setConfigTest.cpp +++ b/src/client/tests/setConfigTest.cpp @@ -5,21 +5,35 @@ #include "tglobal.h" #include "tconfig.h" -/* test parse time function */ -TEST(testCase, set_config_test) { +/* test set config function */ +TEST(testCase, set_config_test1) { const char *config = "{\"debugFlag\":\"131\"}"; taos_set_config(config); const char *config2 = "{\"debugFlag\":\"199\"}"; - taos_set_config(config2); // not take effect + taos_set_config(config2); // not take effect - bool readResult = taosReadGlobalCfg(); - ASSERT_TRUE(readResult); // load file config, not take effect + bool readResult = taosReadGlobalCfg(); // load file config, debugFlag not take effect + ASSERT_TRUE(readResult); int32_t checkResult = taosCheckGlobalCfg(); ASSERT_EQ(checkResult, 0); SGlobalCfg *cfg = taosGetConfigOption("debugFlag"); ASSERT_EQ(cfg->cfgStatus, TAOS_CFG_CSTATUS_OPTION); - int32_t result = *(int32_t*)cfg->ptr; + int32_t result = *(int32_t *)cfg->ptr; ASSERT_EQ(result, 131); } + +TEST(testCase, set_config_test2) { + const char *config = "{\"numOfCommitThreads\":\"10\"}"; + taos_set_config(config); + + bool readResult = taosReadGlobalCfg(); // load file config, debugFlag not take effect + ASSERT_TRUE(readResult); + int32_t checkResult = taosCheckGlobalCfg(); + ASSERT_EQ(checkResult, 0); + + SGlobalCfg *cfg = taosGetConfigOption("numOfCommitThreads"); + int32_t result = *(int32_t*)cfg->ptr; + ASSERT_NE(result, 10); // numOfCommitThreads not type of TSDB_CFG_CTYPE_B_CLIENT +} diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index f73ba9a7aa..e892e7f524 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -89,7 +89,7 @@ void taosDumpGlobalCfg(); void taosInitConfigOption(SGlobalCfg cfg); SGlobalCfg * taosGetConfigOption(const char *option); -bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus); +bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus, int8_t sourceType); #ifdef __cplusplus } diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index e7a8f0639b..d70375721c 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -294,11 +294,12 @@ SGlobalCfg *taosGetConfigOption(const char *option) { } bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, - int8_t cfgStatus) { + int8_t cfgStatus, int8_t sourceType) { bool ret = false; for (int i = 0; i < tsGlobalConfigNum; ++i) { SGlobalCfg *cfg = tsGlobalConfig + i; if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue; + if (sourceType != 0 && !(sourceType & TSDB_CFG_CTYPE_B_CLIENT)) continue; if (strcasecmp(cfg->option, option) != 0) continue; switch (cfg->valType) { @@ -479,7 +480,7 @@ bool taosReadGlobalCfg() { if (vlen3 != 0) value3[vlen3] = 0; } - taosReadConfigOption(option, value, value2, value3, TAOS_CFG_CSTATUS_FILE); + taosReadConfigOption(option, value, value2, value3, TAOS_CFG_CSTATUS_FILE, 0); } fclose(fp); -- GitLab