Merge pull request #8931 from taosdata/feature/dnode3

[TD-10431]<feature> add test cases for dnode
This commit is contained in:
Shengliang Guan 2021-12-05 19:15:17 +08:00 committed by GitHub
commit 8d482158b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 11 deletions

View File

@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "dndTestDeploy.h" #include "deploy.h"
void initLog(char *path) { void initLog(char *path) {
mDebugFlag = 207; mDebugFlag = 207;
@ -80,7 +80,7 @@ void dropServer(SServer* pServer) {
void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
SClient* pClient = (SClient*)parent; SClient* pClient = (SClient*)parent;
pClient->pRsp = pMsg; pClient->pRsp = pMsg;
taosMsleep(100000); //taosMsleep(1000000);
tsem_post(&pClient->sem); tsem_post(&pClient->sem);
} }

View File

@ -2,8 +2,8 @@ add_executable(dndTest01 "")
target_sources(dndTest01 target_sources(dndTest01
PRIVATE PRIVATE
"dndTest01.cpp" "test01.cpp"
"../util/dndTestDeploy.cpp" "../sut/deploy.cpp"
) )
target_link_libraries( target_link_libraries(
@ -18,7 +18,7 @@ target_include_directories(dndTest01
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
"${CMAKE_CURRENT_SOURCE_DIR}/../util" "${CMAKE_CURRENT_SOURCE_DIR}/../sut"
) )
enable_testing() enable_testing()

View File

@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "dndTestDeploy.h" #include "deploy.h"
class DndTest01 : public ::testing::Test { class DndTest01 : public ::testing::Test {
protected: protected:
@ -43,16 +43,16 @@ TEST_F(DndTest01, connectMsg) {
sendMsg(pClient, &rpcMsg); sendMsg(pClient, &rpcMsg);
SConnectRsp* pRsp = (SConnectRsp*)pClient->pRsp; SConnectRsp* pRsp = (SConnectRsp*)pClient->pRsp->pCont;
ASSERT(pRsp); ASSERT_NE(pRsp, nullptr);
pRsp->acctId = htonl(pRsp->acctId); pRsp->acctId = htonl(pRsp->acctId);
pRsp->clusterId = htonl(pRsp->clusterId); pRsp->clusterId = htonl(pRsp->clusterId);
pRsp->connId = htonl(pRsp->connId); pRsp->connId = htonl(pRsp->connId);
pRsp->epSet.port[0] = htonl(pRsp->epSet.port[0]); pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]);
EXPECT_EQ(pRsp->acctId, 1); EXPECT_EQ(pRsp->acctId, 1);
EXPECT_GT(pRsp->clusterId, 0); EXPECT_GT(pRsp->clusterId, 0);
EXPECT_GT(pRsp->connId, 1); EXPECT_EQ(pRsp->connId, 1);
EXPECT_EQ(pRsp->superAuth, 1); EXPECT_EQ(pRsp->superAuth, 1);
EXPECT_EQ(pRsp->readAuth, 1); EXPECT_EQ(pRsp->readAuth, 1);
EXPECT_EQ(pRsp->writeAuth, 1); EXPECT_EQ(pRsp->writeAuth, 1);

View File

@ -137,4 +137,24 @@ bool mndIsMnode(SMnode *pMnode, int32_t dnodeId) {
return true; return true;
} }
void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {} void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) {
SSdb *pSdb = pMnode->pSdb;
pEpSet->numOfEps = 0;
void *pIter = NULL;
while (1) {
SMnodeObj *pMnodeObj = NULL;
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMnodeObj);
if (pIter == NULL) break;
if (pMnodeObj->pDnode == NULL) break;
pEpSet->port[pEpSet->numOfEps] = htons(pMnodeObj->pDnode->port);
tstrncpy(pEpSet->fqdn[pEpSet->numOfEps], pMnodeObj->pDnode->fqdn, TSDB_FQDN_LEN);
if (pMnodeObj->role == TAOS_SYNC_STATE_LEADER) {
pEpSet->inUse = pEpSet->numOfEps;
}
pEpSet->numOfEps++;
}
}

View File

@ -130,6 +130,7 @@ static SConnObj *mndCreateConn(SMnode *pMnode, char *user, uint32_t ip, uint16_t
static void mndFreeConn(SConnObj *pConn) { static void mndFreeConn(SConnObj *pConn) {
tfree(pConn->pQueries); tfree(pConn->pQueries);
tfree(pConn->pStreams); tfree(pConn->pStreams);
tfree(pConn);
mDebug("conn:%d, is destroyed", pConn->connId); mDebug("conn:%d, is destroyed", pConn->connId);
} }

View File

@ -59,6 +59,8 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass); taosEncryptPass((uint8_t *)pass, strlen(pass), userObj.pass);
userObj.createdTime = taosGetTimestampMs(); userObj.createdTime = taosGetTimestampMs();
userObj.updateTime = userObj.createdTime; userObj.updateTime = userObj.createdTime;
userObj.readAuth = 1;
userObj.writeAuth = 1;
if (strcmp(user, TSDB_DEFAULT_USER) == 0) { if (strcmp(user, TSDB_DEFAULT_USER) == 0) {
userObj.superAuth = 1; userObj.superAuth = 1;
@ -95,6 +97,8 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime) SDB_SET_INT64(pRaw, dataPos, pUser->createdTime)
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime) SDB_SET_INT64(pRaw, dataPos, pUser->updateTime)
SDB_SET_INT8(pRaw, dataPos, pUser->superAuth) SDB_SET_INT8(pRaw, dataPos, pUser->superAuth)
SDB_SET_INT8(pRaw, dataPos, pUser->readAuth)
SDB_SET_INT8(pRaw, dataPos, pUser->writeAuth)
SDB_SET_DATALEN(pRaw, dataPos); SDB_SET_DATALEN(pRaw, dataPos);
return pRaw; return pRaw;
@ -121,6 +125,8 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime) SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime)
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime) SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime)
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superAuth) SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superAuth)
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->readAuth)
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->writeAuth)
return pRow; return pRow;
} }
@ -164,6 +170,8 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pSrcUser, SUserObj *pDs
pSrcUser->createdTime = pDstUser->createdTime; pSrcUser->createdTime = pDstUser->createdTime;
pSrcUser->updateTime = pDstUser->updateTime; pSrcUser->updateTime = pDstUser->updateTime;
pSrcUser->superAuth = pDstUser->superAuth; pSrcUser->superAuth = pDstUser->superAuth;
pSrcUser->readAuth = pDstUser->readAuth;
pSrcUser->writeAuth = pDstUser->writeAuth;
return 0; return 0;
} }
@ -185,6 +193,8 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
userObj.createdTime = taosGetTimestampMs(); userObj.createdTime = taosGetTimestampMs();
userObj.updateTime = userObj.createdTime; userObj.updateTime = userObj.createdTime;
userObj.superAuth = 0; userObj.superAuth = 0;
userObj.readAuth = 1;
userObj.writeAuth = 1;
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle); STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
if (pTrans == NULL) return -1; if (pTrans == NULL) return -1;