chore: add test case
This commit is contained in:
parent
2124ef00a7
commit
06c0d99008
|
@ -67,43 +67,50 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC
|
|||
}
|
||||
|
||||
static int32_t hbUpdateUserAuthInfo(SAppHbMgr *pAppHbMgr, SUserAuthBatchRsp *batchRsp) {
|
||||
SClientHbReq *pReq = NULL;
|
||||
while ((pReq = taosHashIterate(pAppHbMgr->activeInfo, pReq))) {
|
||||
STscObj *pTscObj = (STscObj *)acquireTscObj(pReq->connKey.tscRid);
|
||||
if (!pTscObj) {
|
||||
uint64_t clusterId = pAppHbMgr->pAppInstInfo->clusterId;
|
||||
for (int i = 0; i < TARRAY_SIZE(clientHbMgr.appHbMgrs); ++i) {
|
||||
SAppHbMgr *hbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, i);
|
||||
if (!hbMgr || hbMgr->pAppInstInfo->clusterId != clusterId) {
|
||||
continue;
|
||||
}
|
||||
for (int32_t i = 0; i < TARRAY_SIZE(batchRsp->pArray); ++i) {
|
||||
SGetUserAuthRsp *rsp = taosArrayGet(batchRsp->pArray, i);
|
||||
|
||||
if (0 == strncmp(rsp->user, pTscObj->user, TSDB_USER_LEN)) {
|
||||
|
||||
pTscObj->authVer = rsp->version;
|
||||
|
||||
#if 0 // make jenkins happy temporarily. After PR pass, enable these lines again.
|
||||
if (pTscObj->sysInfo != rsp->sysInfo) {
|
||||
tscDebug("update sysInfo of user %s from %" PRIi8 " to %" PRIi8 ", tscRid:%" PRIi64, rsp->user,
|
||||
pTscObj->sysInfo, rsp->sysInfo, pTscObj->id);
|
||||
pTscObj->sysInfo = rsp->sysInfo;
|
||||
}
|
||||
#endif
|
||||
if (pTscObj->passInfo.fp) {
|
||||
SPassInfo *passInfo = &pTscObj->passInfo;
|
||||
int32_t oldVer = atomic_load_32(&passInfo->ver);
|
||||
if (oldVer < rsp->passVer) {
|
||||
atomic_store_32(&passInfo->ver, rsp->passVer);
|
||||
if (passInfo->fp) {
|
||||
(*passInfo->fp)(passInfo->param, &rsp->passVer, TAOS_NOTIFY_PASSVER);
|
||||
}
|
||||
tscDebug("update passVer of user %s from %d to %d, tscRid:%" PRIi64, rsp->user, oldVer,
|
||||
atomic_load_32(&passInfo->ver), pTscObj->id);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
SClientHbReq *pReq = NULL;
|
||||
while ((pReq = taosHashIterate(hbMgr->activeInfo, pReq))) {
|
||||
STscObj *pTscObj = (STscObj *)acquireTscObj(pReq->connKey.tscRid);
|
||||
if (!pTscObj) {
|
||||
continue;
|
||||
}
|
||||
for (int32_t j = 0; j < TARRAY_SIZE(batchRsp->pArray); ++j) {
|
||||
SGetUserAuthRsp *rsp = TARRAY_GET_ELEM(batchRsp->pArray, j);
|
||||
|
||||
if (0 == strncmp(rsp->user, pTscObj->user, TSDB_USER_LEN)) {
|
||||
pTscObj->authVer = rsp->version;
|
||||
|
||||
#if 1 // make jenkins happy temporarily. After PR pass, enable these lines again.
|
||||
if (pTscObj->sysInfo != rsp->sysInfo) {
|
||||
tscDebug("update sysInfo of user %s from %" PRIi8 " to %" PRIi8 ", tscRid:%" PRIi64, rsp->user,
|
||||
pTscObj->sysInfo, rsp->sysInfo, pTscObj->id);
|
||||
pTscObj->sysInfo = rsp->sysInfo;
|
||||
}
|
||||
#endif
|
||||
if (pTscObj->passInfo.fp) {
|
||||
SPassInfo *passInfo = &pTscObj->passInfo;
|
||||
int32_t oldVer = atomic_load_32(&passInfo->ver);
|
||||
if (oldVer < rsp->passVer) {
|
||||
atomic_store_32(&passInfo->ver, rsp->passVer);
|
||||
if (passInfo->fp) {
|
||||
(*passInfo->fp)(passInfo->param, &rsp->passVer, TAOS_NOTIFY_PASSVER);
|
||||
}
|
||||
tscDebug("update passVer of user %s from %d to %d, tscRid:%" PRIi64, rsp->user, oldVer,
|
||||
atomic_load_32(&passInfo->ver), pTscObj->id);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
releaseTscObj(pReq->connKey.tscRid);
|
||||
}
|
||||
releaseTscObj(pReq->connKey.tscRid);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -32,9 +32,21 @@
|
|||
#define nRoot 10
|
||||
#define nUser 10
|
||||
#define USER_LEN 24
|
||||
#define BUF_LEN 256
|
||||
|
||||
typedef uint16_t VarDataLenT;
|
||||
|
||||
#define TSDB_NCHAR_SIZE sizeof(int32_t)
|
||||
#define VARSTR_HEADER_SIZE sizeof(VarDataLenT)
|
||||
|
||||
#define GET_FLOAT_VAL(x) (*(float *)(x))
|
||||
#define GET_DOUBLE_VAL(x) (*(double *)(x))
|
||||
|
||||
#define varDataLen(v) ((VarDataLenT *)(v))[0]
|
||||
|
||||
void createUsers(TAOS *taos, const char *host, char *qstr);
|
||||
void passVerTestMulti(const char *host, char *qstr);
|
||||
void sysInfoTest(const char *host, char *qstr);
|
||||
|
||||
int nPassVerNotified = 0;
|
||||
TAOS *taosu[nRoot] = {0};
|
||||
|
@ -83,6 +95,108 @@ static void queryDB(TAOS *taos, char *command) {
|
|||
taos_free_result(pSql);
|
||||
}
|
||||
|
||||
int printRow(char *str, TAOS_ROW row, TAOS_FIELD *fields, int numFields) {
|
||||
int len = 0;
|
||||
char split = ' ';
|
||||
|
||||
for (int i = 0; i < numFields; ++i) {
|
||||
if (i > 0) {
|
||||
str[len++] = split;
|
||||
}
|
||||
|
||||
if (row[i] == NULL) {
|
||||
len += sprintf(str + len, "%s", "NULL");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (fields[i].type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
len += sprintf(str + len, "%d", *((int8_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
len += sprintf(str + len, "%u", *((uint8_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
len += sprintf(str + len, "%d", *((int16_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
len += sprintf(str + len, "%u", *((uint16_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
len += sprintf(str + len, "%d", *((int32_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
len += sprintf(str + len, "%u", *((uint32_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
len += sprintf(str + len, "%" PRIu64, *((uint64_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float fv = 0;
|
||||
fv = GET_FLOAT_VAL(row[i]);
|
||||
len += sprintf(str + len, "%f", fv);
|
||||
} break;
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double dv = 0;
|
||||
dv = GET_DOUBLE_VAL(row[i]);
|
||||
len += sprintf(str + len, "%lf", dv);
|
||||
} break;
|
||||
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_GEOMETRY: {
|
||||
int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE);
|
||||
memcpy(str + len, row[i], charLen);
|
||||
len += charLen;
|
||||
} break;
|
||||
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
len += sprintf(str + len, "%d", *((int8_t *)row[i]));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static int printResult(TAOS_RES *res, char *output) {
|
||||
int numFields = taos_num_fields(res);
|
||||
TAOS_FIELD *fields = taos_fetch_fields(res);
|
||||
char header[BUF_LEN] = {0};
|
||||
int len = 0;
|
||||
for (int i = 0; i < numFields; ++i) {
|
||||
len += sprintf(header + len, "%s ", fields[i].name);
|
||||
}
|
||||
puts(header);
|
||||
if (output) {
|
||||
strncpy(output, header, BUF_LEN);
|
||||
}
|
||||
|
||||
TAOS_ROW row = NULL;
|
||||
while ((row = taos_fetch_row(res))) {
|
||||
char temp[BUF_LEN] = {0};
|
||||
printRow(temp, row, fields, numFields);
|
||||
puts(temp);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char qstr[1024];
|
||||
|
||||
|
@ -99,6 +213,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
createUsers(taos, argv[1], qstr);
|
||||
passVerTestMulti(argv[1], qstr);
|
||||
sysInfoTest(argv[1], qstr);
|
||||
|
||||
taos_close(taos);
|
||||
taos_cleanup();
|
||||
|
@ -186,10 +301,106 @@ void passVerTestMulti(const char *host, char *qstr) {
|
|||
// sleep(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "######## %s #########\n", __func__);
|
||||
if (nPassVerNotified >= nConn) {
|
||||
fprintf(stderr, "succeed to get passVer notification since nNotify %d >= nConn %d\n", nPassVerNotified, nConn);
|
||||
fprintf(stderr, ">>> succeed to get passVer notification since nNotify %d >= nConn %d\n", nPassVerNotified,
|
||||
nConn);
|
||||
} else {
|
||||
fprintf(stderr, "failed to get passVer notification since nNotify %d < nConn %d\n", nPassVerNotified, nConn);
|
||||
fprintf(stderr, ">>> failed to get passVer notification since nNotify %d < nConn %d\n", nPassVerNotified, nConn);
|
||||
}
|
||||
fprintf(stderr, "######## %s #########\n", __func__);
|
||||
// sleep(300);
|
||||
}
|
||||
|
||||
void sysInfoTest(const char *host, char *qstr) {
|
||||
// root
|
||||
TAOS *taos[nRoot] = {0};
|
||||
char userName[USER_LEN] = "root";
|
||||
|
||||
for (int i = 0; i < nRoot; ++i) {
|
||||
taos[i] = taos_connect(host, "root", "taos", NULL, 0);
|
||||
if (taos[i] == NULL) {
|
||||
fprintf(stderr, "failed to connect to server, reason:%s\n", "null taos" /*taos_errstr(taos)*/);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
queryDB(taos[0], "create database if not exists demo11 vgroups 1 minrows 10");
|
||||
queryDB(taos[0], "create database if not exists demo12 vgroups 1 minrows 10");
|
||||
queryDB(taos[0], "create database if not exists demo13 vgroups 1 minrows 10");
|
||||
|
||||
queryDB(taos[0], "create table demo11.stb (ts timestamp, c1 int) tags(t1 int)");
|
||||
queryDB(taos[0], "create table demo12.stb (ts timestamp, c1 int) tags(t1 int)");
|
||||
queryDB(taos[0], "create table demo13.stb (ts timestamp, c1 int) tags(t1 int)");
|
||||
|
||||
sprintf(qstr, "show grants");
|
||||
char output[BUF_LEN];
|
||||
TAOS_RES *res = NULL;
|
||||
int32_t nRep = 0;
|
||||
|
||||
_REP:
|
||||
fprintf(stderr, "######## %s loop:%d #########\n", __func__, nRep);
|
||||
res = taos_query(taos[0], qstr);
|
||||
if (taos_errno(res) != 0) {
|
||||
fprintf(stderr, "%s:%d failed to execute: %s since %s\n", __func__, __LINE__, qstr, taos_errstr(res));
|
||||
taos_free_result(res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printResult(res, output);
|
||||
taos_free_result(res);
|
||||
if (!strstr(output, "timeseries")) {
|
||||
fprintf(stderr, "%s:%d expected output: 'timeseries' not occur\n", __func__, __LINE__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
queryDB(taos[0], "alter user root sysinfo 0");
|
||||
|
||||
fprintf(stderr, "%s:%d sleep 2 seconds to wait HB take effect\n", __func__, __LINE__);
|
||||
for (int i = 1; i <= 2; ++i) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
res = taos_query(taos[0], qstr);
|
||||
if (taos_errno(res) != 0) {
|
||||
if (!strstr(taos_errstr(res), "Permission denied")) {
|
||||
fprintf(stderr, "%s:%d expected error: 'Permission denied' not occur\n", __func__, __LINE__);
|
||||
taos_free_result(res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
queryDB(taos[0], "alter user root sysinfo 1");
|
||||
fprintf(stderr, "%s:%d sleep 2 seconds to wait HB take effect\n", __func__, __LINE__);
|
||||
for (int i = 1; i <= 2; ++i) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
res = taos_query(taos[0], qstr);
|
||||
int32_t code = taos_errno(res);
|
||||
if (code != 0) {
|
||||
fprintf(stderr, "%s:%d failed to execute: %s since %s\n", __func__, __LINE__, qstr, taos_errstr(res));
|
||||
taos_free_result(res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
printResult(res, output);
|
||||
taos_free_result(res);
|
||||
if (!strstr(output, "timeseries")) {
|
||||
fprintf(stderr, "%s:%d expected output: 'timeseries' not occur\n", __func__, __LINE__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if(++nRep < 5) {
|
||||
goto _REP;
|
||||
}
|
||||
|
||||
// close the taos_conn
|
||||
for (int i = 0; i < nRoot; ++i) {
|
||||
taos_close(taos[i]);
|
||||
fprintf(stderr, "%s:%d close taos[%d]\n", __func__, __LINE__, i);
|
||||
}
|
||||
|
||||
fprintf(stderr, "######## %s #########\n", __func__);
|
||||
fprintf(stderr, ">>> succeed to run sysInfoTest\n");
|
||||
fprintf(stderr, "######## %s #########\n", __func__);
|
||||
}
|
Loading…
Reference in New Issue