提交 7965b4c7 编写于 作者: wmmhello's avatar wmmhello

[TD-5992] add test case

上级 48281dbf
......@@ -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;
}
}
......
......@@ -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
}
......@@ -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
}
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册