fix: improve test coverage
This commit is contained in:
parent
67ed0cf313
commit
5c928eac6a
|
@ -228,7 +228,7 @@
|
||||||
./test.sh -f tsim/table/vgroup.sim
|
./test.sh -f tsim/table/vgroup.sim
|
||||||
|
|
||||||
# ---- stream
|
# ---- stream
|
||||||
./test.sh -f tsim/stream/basic0.sim
|
./test.sh -f tsim/stream/basic0.sim -v
|
||||||
./test.sh -f tsim/stream/basic1.sim
|
./test.sh -f tsim/stream/basic1.sim
|
||||||
./test.sh -f tsim/stream/basic2.sim
|
./test.sh -f tsim/stream/basic2.sim
|
||||||
./test.sh -f tsim/stream/drop_stream.sim
|
./test.sh -f tsim/stream/drop_stream.sim
|
||||||
|
|
|
@ -12,14 +12,14 @@ $tb = $tbPrefix . $i
|
||||||
print =============== step1
|
print =============== step1
|
||||||
sql drop database -x step1
|
sql drop database -x step1
|
||||||
step1:
|
step1:
|
||||||
sql create database $db vgroups 2
|
sql create database $db vgroups 2 precision 'ns'
|
||||||
sql use $db
|
sql use $db
|
||||||
sql create table $tb (ts timestamp, speed int)
|
sql create table $tb (ts timestamp, speed int)
|
||||||
|
|
||||||
$x = 0
|
$x = 0
|
||||||
while $x < 10
|
while $x < 110
|
||||||
$cc = $x * 60000
|
$cc = $x * 60000
|
||||||
$ms = 1601481600000 + $cc
|
$ms = 1601481600000000000 + $cc
|
||||||
|
|
||||||
sql insert into $tb values ($ms , $x )
|
sql insert into $tb values ($ms , $x )
|
||||||
$x = $x + 1
|
$x = $x + 1
|
||||||
|
@ -27,9 +27,9 @@ endw
|
||||||
|
|
||||||
print =============== step 2
|
print =============== step 2
|
||||||
$x = 0
|
$x = 0
|
||||||
while $x < 5
|
while $x < 110
|
||||||
$cc = $x * 60000
|
$cc = $x * 60000
|
||||||
$ms = 1551481600000 + $cc
|
$ms = 1551481600000000000 + $cc
|
||||||
|
|
||||||
sql insert into $tb values ($ms , $x )
|
sql insert into $tb values ($ms , $x )
|
||||||
$x = $x + 1
|
$x = $x + 1
|
||||||
|
@ -38,8 +38,29 @@ endw
|
||||||
sql select * from $tb
|
sql select * from $tb
|
||||||
|
|
||||||
print $rows points data are retrieved
|
print $rows points data are retrieved
|
||||||
if $rows != 15 then
|
if $rows != 220 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
# error
|
||||||
|
print $data1
|
||||||
|
print $data[1000][1]
|
||||||
|
print $data[1][1000]
|
||||||
|
print $data[1000][1000]
|
||||||
|
$a1 = 0
|
||||||
|
$a2 = 0
|
||||||
|
$a3 = $a1 % $a2
|
||||||
|
print $a3
|
||||||
|
|
||||||
|
$val = \\\1
|
||||||
|
print ====> $val
|
||||||
|
|
||||||
|
sql_slow select * from $tb
|
||||||
|
|
||||||
|
sql close
|
||||||
|
sql connect
|
||||||
|
sql close
|
||||||
|
sql connect root
|
||||||
|
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
system sh/stop_dnodes.sh
|
system sh/stop_dnodes.sh
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
system sh/cfg.sh -n dnode1 -c debugflag -v 131
|
system sh/cfg.sh -n dnode1 -c debugflag -v 131
|
||||||
system sh/exec.sh -n dnode1 -s start -v
|
system sh/exec.sh -n dnode1 -s start
|
||||||
sql connect
|
sql connect
|
||||||
|
|
||||||
print =============== create database
|
print =============== create database
|
||||||
|
|
|
@ -21,35 +21,20 @@ void simLogSql(char *sql, bool useSharp) {
|
||||||
char filename[256];
|
char filename[256];
|
||||||
sprintf(filename, "%s/sim.sql", simScriptDir);
|
sprintf(filename, "%s/sim.sql", simScriptDir);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
// fp = fopen(filename, "w");
|
|
||||||
pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM);
|
pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) {
|
}
|
||||||
fprintf(stderr, "ERROR: failed to open file: %s\n", filename);
|
|
||||||
return;
|
if (pFile != NULL) {
|
||||||
|
if (useSharp) {
|
||||||
|
taosFprintfFile(pFile, "# %s;\n", sql);
|
||||||
|
} else {
|
||||||
|
taosFprintfFile(pFile, "%s;\n", sql);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (useSharp) {
|
|
||||||
taosFprintfFile(pFile, "# %s;\n", sql);
|
|
||||||
} else {
|
|
||||||
taosFprintfFile(pFile, "%s;\n", sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
taosFsyncFile(pFile);
|
taosFsyncFile(pFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
char *simParseArbitratorName(char *varName) {
|
|
||||||
static char hostName[140];
|
|
||||||
#ifdef WINDOWS
|
|
||||||
taosGetFqdn(hostName);
|
|
||||||
sprintf(&hostName[strlen(hostName)], ":%d", 8000);
|
|
||||||
#else
|
|
||||||
sprintf(hostName, "%s:%d", "localhost", 8000);
|
|
||||||
#endif
|
|
||||||
return hostName;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *simParseHostName(char *varName) {
|
char *simParseHostName(char *varName) {
|
||||||
static char hostName[140];
|
static char hostName[140];
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
@ -65,18 +50,18 @@ char *simParseHostName(char *varName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void simFindFirstNum(const char *begin, int32_t beginLen, int32_t *num) {
|
static void simFindFirstNum(const char *begin, int32_t beginLen, int32_t *num) {
|
||||||
if (beginLen <= 5) {
|
*num = 0;
|
||||||
*num = 0;
|
|
||||||
} else {
|
if (beginLen > 5) {
|
||||||
*num = atoi(begin + 5);
|
*num = atoi(begin + 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void simFindSecondNum(const char *begin, int32_t beginLen, int32_t *num) {
|
static void simFindSecondNum(const char *begin, int32_t beginLen, int32_t *num) {
|
||||||
|
*num = 0;
|
||||||
|
|
||||||
const char *number = strstr(begin, "][");
|
const char *number = strstr(begin, "][");
|
||||||
if (number == NULL) {
|
if (number != NULL) {
|
||||||
*num = 0;
|
|
||||||
} else {
|
|
||||||
*num = atoi(number + 2);
|
*num = atoi(number + 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,10 +76,10 @@ static void simFindFirstKeyVal(const char *begin, int32_t beginLen, char *key, i
|
||||||
}
|
}
|
||||||
|
|
||||||
static void simFindSecondKeyNum(const char *begin, int32_t beginLen, int32_t *num) {
|
static void simFindSecondKeyNum(const char *begin, int32_t beginLen, int32_t *num) {
|
||||||
|
*num = 0;
|
||||||
|
|
||||||
const char *number = strstr(begin, ")[");
|
const char *number = strstr(begin, ")[");
|
||||||
if (number == NULL) {
|
if (number != NULL) {
|
||||||
*num = 0;
|
|
||||||
} else {
|
|
||||||
*num = atoi(number + 2);
|
*num = atoi(number + 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,12 +89,6 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
|
||||||
return simParseHostName(varName);
|
return simParseHostName(varName);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (strncmp(varName, "arbitrator", 10) == 0) {
|
|
||||||
return simParseArbitratorName(varName);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (strncmp(varName, "error", varLen) == 0) return script->error;
|
if (strncmp(varName, "error", varLen) == 0) return script->error;
|
||||||
|
|
||||||
if (strncmp(varName, "rows", varLen) == 0) return script->rows;
|
if (strncmp(varName, "rows", varLen) == 0) return script->rows;
|
||||||
|
@ -153,9 +132,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
|
||||||
} else if (varName[5] == '_') {
|
} else if (varName[5] == '_') {
|
||||||
// data2_db
|
// data2_db
|
||||||
int32_t col = varName[4] - '0';
|
int32_t col = varName[4] - '0';
|
||||||
if (col < 0 || col >= MAX_QUERY_COL_NUM) {
|
col = col % MAX_QUERY_COL_NUM;
|
||||||
return "null";
|
|
||||||
}
|
|
||||||
|
|
||||||
char *keyName;
|
char *keyName;
|
||||||
int32_t keyLen;
|
int32_t keyLen;
|
||||||
|
@ -171,9 +148,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
|
||||||
} else if (varName[6] == '_') {
|
} else if (varName[6] == '_') {
|
||||||
// data21_db
|
// data21_db
|
||||||
int32_t col = (varName[4] - '0') * 10 + (varName[5] - '0');
|
int32_t col = (varName[4] - '0') * 10 + (varName[5] - '0');
|
||||||
if (col < 0 || col >= MAX_QUERY_COL_NUM) {
|
col = col % MAX_QUERY_COL_NUM;
|
||||||
return "null";
|
|
||||||
}
|
|
||||||
|
|
||||||
char *keyName;
|
char *keyName;
|
||||||
int32_t keyLen;
|
int32_t keyLen;
|
||||||
|
@ -185,17 +160,12 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
|
||||||
return script->data[i][col];
|
return script->data[i][col];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "null";
|
|
||||||
} else {
|
} else {
|
||||||
// $data00
|
// $data00
|
||||||
int32_t row = varName[4] - '0';
|
int32_t row = varName[4] - '0';
|
||||||
int32_t col = varName[5] - '0';
|
int32_t col = varName[5] - '0';
|
||||||
if (row < 0 || row >= MAX_QUERY_ROW_NUM) {
|
row = row % MAX_QUERY_ROW_NUM;
|
||||||
return "null";
|
col = col % MAX_QUERY_COL_NUM;
|
||||||
}
|
|
||||||
if (col < 0 || col >= MAX_QUERY_COL_NUM) {
|
|
||||||
return "null";
|
|
||||||
}
|
|
||||||
|
|
||||||
simDebug("script:%s, data[%d][%d]=%s", script->fileName, row, col, script->data[row][col]);
|
simDebug("script:%s, data[%d][%d]=%s", script->fileName, row, col, script->data[row][col]);
|
||||||
return script->data[row][col];
|
return script->data[row][col];
|
||||||
|
@ -253,9 +223,9 @@ int32_t simExecuteExpression(SScript *script, char *exp) {
|
||||||
rest = paGetToken(rest, &op2, &op2Len);
|
rest = paGetToken(rest, &op2, &op2Len);
|
||||||
|
|
||||||
if (var1[0] == '$')
|
if (var1[0] == '$')
|
||||||
strcpy(t0, simGetVariable(script, var1 + 1, var1Len - 1));
|
tstrncpy(t0, simGetVariable(script, var1 + 1, var1Len - 1), sizeof(t0));
|
||||||
else {
|
else {
|
||||||
memcpy(t0, var1, var1Len);
|
tstrncpy(t0, var1, var1Len);
|
||||||
t0[var1Len] = 0;
|
t0[var1Len] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,6 +548,8 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
|
||||||
while (1) {
|
while (1) {
|
||||||
var = strchr(src, '$');
|
var = strchr(src, '$');
|
||||||
if (var == NULL) break;
|
if (var == NULL) break;
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (var && ((var - src - 1) > 0) && *(var - 1) == '\\') {
|
if (var && ((var - src - 1) > 0) && *(var - 1) == '\\') {
|
||||||
srcLen = (int32_t)(var - src - 1);
|
srcLen = (int32_t)(var - src - 1);
|
||||||
memcpy(dst + dstLen, src, srcLen);
|
memcpy(dst + dstLen, src, srcLen);
|
||||||
|
@ -585,6 +557,7 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
|
||||||
src = var;
|
src = var;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
srcLen = (int32_t)(var - src);
|
srcLen = (int32_t)(var - src);
|
||||||
memcpy(dst + dstLen, src, srcLen);
|
memcpy(dst + dstLen, src, srcLen);
|
||||||
|
@ -657,11 +630,11 @@ bool simCreateTaosdConnect(SScript *script, char *rest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
|
bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
|
||||||
char timeStr[80] = {0};
|
char timeStr[80] = {0};
|
||||||
time_t tt;
|
time_t tt;
|
||||||
struct tm tp;
|
struct tm tp;
|
||||||
SCmdLine *line = &script->lines[script->linePos];
|
SCmdLine *line = &script->lines[script->linePos];
|
||||||
int32_t ret = -1;
|
int32_t ret = -1;
|
||||||
|
|
||||||
TAOS_RES *pSql = NULL;
|
TAOS_RES *pSql = NULL;
|
||||||
|
|
||||||
|
@ -705,17 +678,6 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
int32_t num_fields = taos_field_count(pSql);
|
int32_t num_fields = taos_field_count(pSql);
|
||||||
if (num_fields != 0) {
|
if (num_fields != 0) {
|
||||||
if (pSql == NULL) {
|
|
||||||
simDebug("script:%s, taos:%p, %s failed, result is null", script->fileName, script->taos, rest);
|
|
||||||
if (line->errorJump == SQL_JUMP_TRUE) {
|
|
||||||
script->linePos = line->jump;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(script->error, "lineNum:%d. result set null, sql:%s", line->lineNum, rest);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
TAOS_ROW row;
|
TAOS_ROW row;
|
||||||
|
|
||||||
while ((row = taos_fetch_row(pSql))) {
|
while ((row = taos_fetch_row(pSql))) {
|
||||||
|
@ -942,30 +904,6 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(rest, "connect", 7) == 0) {
|
|
||||||
if (!simCreateTaosdConnect(script, rest)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
script->linePos++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (script->taos == NULL) {
|
|
||||||
if (!simCreateTaosdConnect(script, "connect root")) {
|
|
||||||
if (line->errorJump == SQL_JUMP_TRUE) {
|
|
||||||
script->linePos = line->jump;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strncmp(rest, "close", 5) == 0) {
|
|
||||||
simCloseTaosdConnect(script);
|
|
||||||
script->linePos++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TAOS_RES *pSql = taos_query(script->taos, rest);
|
TAOS_RES *pSql = taos_query(script->taos, rest);
|
||||||
int32_t ret = taos_errno(pSql);
|
int32_t ret = taos_errno(pSql);
|
||||||
taos_free_result(pSql);
|
taos_free_result(pSql);
|
||||||
|
|
|
@ -717,20 +717,12 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
|
bool simParseSqlSlowCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
|
||||||
simParseSqlCmd(rest, pCmd, lineNum);
|
simParseSqlCmd(rest, pCmd, lineNum);
|
||||||
cmdLine[numOfLines - 1].cmdno = SIM_CMD_SQL_SLOW;
|
cmdLine[numOfLines - 1].cmdno = SIM_CMD_SQL_SLOW;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool simParseRestfulCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
|
|
||||||
simParseSqlCmd(rest, pCmd, lineNum);
|
|
||||||
cmdLine[numOfLines - 1].cmdno = SIM_CMD_RESTFUL;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool simParseSystemCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
|
bool simParseSystemCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
|
||||||
int32_t expLen;
|
int32_t expLen;
|
||||||
|
|
||||||
|
@ -1058,7 +1050,6 @@ void simInitsimCmdList() {
|
||||||
simCmdList[cmdno].executeCmd = simExecuteSqlErrorCmd;
|
simCmdList[cmdno].executeCmd = simExecuteSqlErrorCmd;
|
||||||
simAddCmdIntoHash(&(simCmdList[cmdno]));
|
simAddCmdIntoHash(&(simCmdList[cmdno]));
|
||||||
|
|
||||||
#if 0
|
|
||||||
cmdno = SIM_CMD_SQL_SLOW;
|
cmdno = SIM_CMD_SQL_SLOW;
|
||||||
simCmdList[cmdno].cmdno = cmdno;
|
simCmdList[cmdno].cmdno = cmdno;
|
||||||
strcpy(simCmdList[cmdno].name, "sql_slow");
|
strcpy(simCmdList[cmdno].name, "sql_slow");
|
||||||
|
@ -1067,15 +1058,6 @@ void simInitsimCmdList() {
|
||||||
simCmdList[cmdno].executeCmd = simExecuteSqlSlowCmd;
|
simCmdList[cmdno].executeCmd = simExecuteSqlSlowCmd;
|
||||||
simAddCmdIntoHash(&(simCmdList[cmdno]));
|
simAddCmdIntoHash(&(simCmdList[cmdno]));
|
||||||
|
|
||||||
cmdno = SIM_CMD_RESTFUL;
|
|
||||||
simCmdList[cmdno].cmdno = cmdno;
|
|
||||||
strcpy(simCmdList[cmdno].name, "restful");
|
|
||||||
simCmdList[cmdno].nlen = (int16_t)strlen(simCmdList[cmdno].name);
|
|
||||||
simCmdList[cmdno].parseCmd = simParseRestfulCmd;
|
|
||||||
simCmdList[cmdno].executeCmd = simExecuteRestfulCmd;
|
|
||||||
simAddCmdIntoHash(&(simCmdList[cmdno]));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* test is only an internal command */
|
/* test is only an internal command */
|
||||||
cmdno = SIM_CMD_TEST;
|
cmdno = SIM_CMD_TEST;
|
||||||
simCmdList[cmdno].cmdno = cmdno;
|
simCmdList[cmdno].cmdno = cmdno;
|
||||||
|
|
Loading…
Reference in New Issue