TDengine/source/dnode/mnode/impl/test/profile/profile.cpp

322 lines
9.8 KiB
C++
Raw Permalink Normal View History

2021-12-16 09:07:40 +00:00
/**
2021-12-16 12:16:35 +00:00
* @file profile.cpp
2021-12-16 09:07:40 +00:00
* @author slguan (slguan@taosdata.com)
2022-01-06 08:13:49 +00:00
* @brief MNODE module profile tests
* @version 1.0
* @date 2022-01-06
2021-12-04 02:23:39 +00:00
*
2022-01-06 08:13:49 +00:00
* @copyright Copyright (c) 2022
2021-12-04 02:23:39 +00:00
*
*/
2022-01-04 12:36:54 +00:00
#include "sut.h"
2021-12-04 02:23:39 +00:00
2022-01-06 08:13:49 +00:00
class MndTestProfile : public ::testing::Test {
2021-12-04 02:23:39 +00:00
protected:
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_profile", 9031); }
2021-12-22 10:39:32 +00:00
static void TearDownTestSuite() { test.Cleanup(); }
2021-12-04 02:23:39 +00:00
2021-12-22 10:39:32 +00:00
static Testbase test;
2022-01-05 10:08:56 +00:00
static int32_t connId;
2021-12-21 14:35:45 +00:00
public:
void SetUp() override {}
void TearDown() override {}
2021-12-04 02:23:39 +00:00
};
2022-01-06 08:13:49 +00:00
Testbase MndTestProfile::test;
int32_t MndTestProfile::connId;
2021-12-05 12:28:27 +00:00
2022-01-06 08:13:49 +00:00
TEST_F(MndTestProfile, 01_ConnectMsg) {
2022-02-16 03:45:44 +00:00
SConnectReq connectReq = {0};
connectReq.pid = 1234;
2022-04-21 07:24:12 +00:00
char passwd[] = "taosdata";
char secretEncrypt[sizeof(connectReq.passwd)+1] = {0};
2022-04-21 07:24:12 +00:00
taosEncryptPass_c((uint8_t*)passwd, strlen(passwd), secretEncrypt);
size_t n = strnlen(secretEncrypt, sizeof(secretEncrypt));
ASSERT_EQ(n, sizeof(connectReq.passwd));
2022-04-21 07:24:12 +00:00
2022-02-16 03:45:44 +00:00
strcpy(connectReq.app, "mnode_test_profile");
strcpy(connectReq.db, "");
2022-04-21 07:24:12 +00:00
strcpy(connectReq.user, "root");
memcpy(connectReq.passwd, secretEncrypt, sizeof(connectReq.passwd));
2024-11-04 12:22:14 +00:00
strcpy(connectReq.sVer, td_version);
2025-12-29 14:08:38 +00:00
connectReq.connectTime = taosGetTimestampMs();
tSignConnectReq(&connectReq);
2021-12-05 12:28:27 +00:00
2022-02-16 03:45:44 +00:00
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSConnectReq(pReq, contLen, &connectReq);
2021-12-04 02:23:39 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
2021-12-06 06:38:37 +00:00
ASSERT_NE(pMsg, nullptr);
2021-12-22 10:39:32 +00:00
ASSERT_EQ(pMsg->code, 0);
2021-12-04 02:23:39 +00:00
2022-02-16 03:45:44 +00:00
SConnectRsp connectRsp = {0};
tDeserializeSConnectRsp(pMsg->pCont, pMsg->contLen, &connectRsp);
2021-12-04 02:23:39 +00:00
2022-02-16 03:45:44 +00:00
EXPECT_EQ(connectRsp.acctId, 1);
EXPECT_GT(connectRsp.clusterId, 0);
2022-04-15 06:31:54 +00:00
EXPECT_NE(connectRsp.connId, 0);
2022-02-16 03:45:44 +00:00
EXPECT_EQ(connectRsp.superUser, 1);
2021-12-04 02:23:39 +00:00
2024-12-06 06:17:43 +00:00
EXPECT_EQ(connectRsp.epSet.eps[0].port, 9031);
EXPECT_STREQ(connectRsp.epSet.eps[0].fqdn, "localhost");
2021-12-06 06:38:37 +00:00
2022-02-16 03:45:44 +00:00
connId = connectRsp.connId;
2021-12-04 02:23:39 +00:00
}
TEST_F(MndTestProfile, 02_ConnectMsg_NotExistDB) {
2022-04-21 07:24:12 +00:00
char passwd[] = "taosdata";
SConnectReq connectReq = {0};
char secretEncrypt[sizeof(connectReq.passwd)+1] = {0};
2022-04-21 07:24:12 +00:00
taosEncryptPass_c((uint8_t*)passwd, strlen(passwd), secretEncrypt);
size_t n = strnlen(secretEncrypt, sizeof(secretEncrypt));
ASSERT_EQ(n, sizeof(connectReq.passwd));
2022-04-21 07:24:12 +00:00
2022-02-16 03:45:44 +00:00
connectReq.pid = 1234;
strcpy(connectReq.app, "mnode_test_profile");
strcpy(connectReq.db, "not_exist_db");
2022-04-21 07:24:12 +00:00
strcpy(connectReq.user, "root");
memcpy(connectReq.passwd, secretEncrypt, sizeof(connectReq.passwd));
2024-11-04 12:19:41 +00:00
strcpy(connectReq.sVer, td_version);
2025-12-29 14:08:38 +00:00
connectReq.connectTime = taosGetTimestampMs();
tSignConnectReq(&connectReq);
2021-12-06 06:38:37 +00:00
2022-02-16 03:45:44 +00:00
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSConnectReq(pReq, contLen, &connectReq);
2021-12-06 06:38:37 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DB_NOT_EXIST);
2022-01-05 12:18:56 +00:00
ASSERT_EQ(pRsp->contLen, 0);
2021-12-06 06:38:37 +00:00
}
2022-01-06 08:13:49 +00:00
TEST_F(MndTestProfile, 03_ConnectMsg_Show) {
2022-08-02 05:47:04 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_CONNS, "perf_connections", "");
2024-12-05 09:00:57 +00:00
EXPECT_EQ(test.GetShowRows(), 1);
2021-12-06 06:38:37 +00:00
}
2022-01-06 08:13:49 +00:00
TEST_F(MndTestProfile, 04_HeartBeatMsg) {
2022-02-14 07:27:38 +00:00
SClientHbBatchReq batchReq = {0};
2022-01-14 07:54:07 +00:00
batchReq.reqs = taosArrayInit(0, sizeof(SClientHbReq));
SClientHbReq req = {0};
2022-04-15 06:31:54 +00:00
req.connKey.tscRid = 123;
req.connKey.connType = CONN_TYPE__TMQ;
2022-01-14 07:54:07 +00:00
req.info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
2022-02-14 07:27:38 +00:00
SKv kv = {0};
2022-01-26 00:50:32 +00:00
kv.key = 123;
2022-01-14 07:54:07 +00:00
kv.value = (void*)"bcd";
kv.valueLen = 4;
2022-01-27 05:52:10 +00:00
taosHashPut(req.info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
2022-01-14 07:54:07 +00:00
taosArrayPush(batchReq.reqs, &req);
2022-02-14 07:27:38 +00:00
int32_t tlen = tSerializeSClientHbBatchReq(NULL, 0, &batchReq);
void* buf = (SClientHbBatchReq*)rpcMallocCont(tlen);
tSerializeSClientHbBatchReq(buf, tlen, &batchReq);
2022-01-14 07:54:07 +00:00
SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, buf, tlen);
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
2022-02-14 07:27:38 +00:00
2022-01-14 07:54:07 +00:00
SClientHbBatchRsp rsp = {0};
2022-02-14 07:27:38 +00:00
tDeserializeSClientHbBatchRsp(pMsg->pCont, pMsg->contLen, &rsp);
2022-01-14 07:54:07 +00:00
int sz = taosArrayGetSize(rsp.rsps);
ASSERT_EQ(sz, 1);
2022-02-14 07:27:38 +00:00
// SClientHbRsp* pRsp = (SClientHbRsp*) taosArrayGet(rsp.rsps, 0);
// EXPECT_EQ(pRsp->connKey.connId, 123);
// EXPECT_EQ(pRsp->connKey.hbType, HEARTBEAT_TYPE_MQ);
// EXPECT_EQ(pRsp->status, 0);
2022-01-14 08:45:15 +00:00
2022-01-14 07:54:07 +00:00
#if 0
2022-01-06 08:13:49 +00:00
int32_t contLen = sizeof(SHeartBeatReq);
2021-12-05 12:28:27 +00:00
2022-01-06 08:13:49 +00:00
SHeartBeatReq* pReq = (SHeartBeatReq*)rpcMallocCont(contLen);
2021-12-06 06:38:37 +00:00
pReq->connId = htonl(connId);
2021-12-05 12:28:27 +00:00
pReq->pid = htonl(1234);
pReq->numOfQueries = htonl(0);
pReq->numOfStreams = htonl(0);
2022-01-06 08:13:49 +00:00
strcpy(pReq->app, "mnode_test_profile");
2021-12-05 12:28:27 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
2021-12-06 06:38:37 +00:00
ASSERT_NE(pMsg, nullptr);
2021-12-22 10:39:32 +00:00
ASSERT_EQ(pMsg->code, 0);
2021-12-05 12:28:27 +00:00
2021-12-06 06:38:37 +00:00
SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
2021-12-05 12:28:27 +00:00
ASSERT_NE(pRsp, nullptr);
pRsp->connId = htonl(pRsp->connId);
pRsp->queryId = htonl(pRsp->queryId);
pRsp->streamId = htonl(pRsp->streamId);
pRsp->totalDnodes = htonl(pRsp->totalDnodes);
pRsp->onlineDnodes = htonl(pRsp->onlineDnodes);
pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]);
2021-12-06 06:38:37 +00:00
EXPECT_EQ(pRsp->connId, connId);
2021-12-05 12:28:27 +00:00
EXPECT_EQ(pRsp->queryId, 0);
EXPECT_EQ(pRsp->streamId, 0);
EXPECT_EQ(pRsp->totalDnodes, 1);
EXPECT_EQ(pRsp->onlineDnodes, 1);
EXPECT_EQ(pRsp->killConnection, 0);
EXPECT_EQ(pRsp->epSet.inUse, 0);
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
2022-01-11 11:41:38 +00:00
EXPECT_EQ(pRsp->epSet.port[0], 9031);
2021-12-05 12:28:27 +00:00
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
2022-01-14 07:54:07 +00:00
#endif
2021-12-05 12:28:27 +00:00
}
2021-12-06 06:38:37 +00:00
2022-01-06 08:13:49 +00:00
TEST_F(MndTestProfile, 05_KillConnMsg) {
2022-01-14 07:54:07 +00:00
// temporary remove since kill will use new heartbeat msg
#if 0
2021-12-06 06:38:37 +00:00
{
2022-02-16 09:33:07 +00:00
SKillConnReq killReq = {0};
killReq.connId = connId;
2021-12-06 06:38:37 +00:00
2022-02-16 09:33:07 +00:00
int32_t contLen = tSerializeSKillConnReq(NULL, 0, &killReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSKillConnReq(pReq, contLen, &killReq);
2021-12-06 06:38:37 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-06 06:38:37 +00:00
}
{
2022-01-06 08:13:49 +00:00
int32_t contLen = sizeof(SHeartBeatReq);
2021-12-22 10:39:32 +00:00
2022-01-06 08:13:49 +00:00
SHeartBeatReq* pReq = (SHeartBeatReq*)rpcMallocCont(contLen);
2021-12-06 06:38:37 +00:00
pReq->connId = htonl(connId);
pReq->pid = htonl(1234);
pReq->numOfQueries = htonl(0);
pReq->numOfStreams = htonl(0);
2022-01-06 08:13:49 +00:00
strcpy(pReq->app, "mnode_test_profile");
2021-12-06 06:38:37 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONNECTION);
ASSERT_EQ(pRsp->contLen, 0);
2021-12-06 06:38:37 +00:00
}
{
2022-02-16 03:45:44 +00:00
SConnectReq connectReq = {0};
connectReq.pid = 1234;
strcpy(connectReq.app, "mnode_test_profile");
strcpy(connectReq.db, "invalid_db");
2021-12-22 10:39:32 +00:00
2022-02-16 03:45:44 +00:00
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSConnectReq(pReq, contLen, &connectReq);
2021-12-06 06:38:37 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
2021-12-06 06:38:37 +00:00
ASSERT_NE(pMsg, nullptr);
2021-12-22 10:39:32 +00:00
ASSERT_EQ(pMsg->code, 0);
2021-12-06 06:38:37 +00:00
2022-02-16 03:45:44 +00:00
SConnectRsp connectRsp = {0};
tDeserializeSConnectRsp(pMsg->pCont, pMsg->contLen, &connectRsp);
EXPECT_EQ(connectRsp.acctId, 1);
EXPECT_GT(connectRsp.clusterId, 0);
EXPECT_GT(connectRsp.connId, connId);
EXPECT_EQ(connectRsp.superUser, 1);
EXPECT_EQ(connectRsp.epSet.inUse, 0);
EXPECT_EQ(connectRsp.epSet.numOfEps, 1);
EXPECT_EQ(connectRsp.epSet.port[0], 9031);
EXPECT_STREQ(connectRsp.epSet.fqdn[0], "localhost");
connId = connectRsp.connId;
2021-12-06 06:38:37 +00:00
}
2022-01-14 07:54:07 +00:00
#endif
2021-12-06 06:38:37 +00:00
}
2022-01-06 08:13:49 +00:00
TEST_F(MndTestProfile, 06_KillConnMsg_InvalidConn) {
2022-02-16 09:33:07 +00:00
SKillConnReq killReq = {0};
killReq.connId = 2345;
2021-12-06 06:38:37 +00:00
2022-02-16 09:33:07 +00:00
int32_t contLen = tSerializeSKillConnReq(NULL, 0, &killReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSKillConnReq(pReq, contLen, &killReq);
2021-12-06 06:38:37 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID);
2021-12-06 06:38:37 +00:00
}
2022-01-06 08:13:49 +00:00
TEST_F(MndTestProfile, 07_KillQueryMsg) {
2022-01-14 07:54:07 +00:00
// temporary remove since kill will use new heartbeat msg
#if 0
2021-12-06 06:38:37 +00:00
{
2022-02-16 09:33:07 +00:00
SKillQueryReq killReq = {0};
killReq.connId = connId;
killReq.queryId = 1234;
2021-12-22 10:39:32 +00:00
2022-02-16 09:33:07 +00:00
int32_t contLen = tSerializeSKillQueryReq(NULL, 0, &killReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSKillQueryReq(pReq, contLen, &killReq);
2021-12-06 06:38:37 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
ASSERT_EQ(pRsp->contLen, 0);
2021-12-06 06:38:37 +00:00
}
{
2022-01-06 08:13:49 +00:00
int32_t contLen = sizeof(SHeartBeatReq);
2021-12-22 10:39:32 +00:00
2022-01-06 08:13:49 +00:00
SHeartBeatReq* pReq = (SHeartBeatReq*)rpcMallocCont(contLen);
2021-12-06 06:38:37 +00:00
pReq->connId = htonl(connId);
pReq->pid = htonl(1234);
pReq->numOfQueries = htonl(0);
pReq->numOfStreams = htonl(0);
2022-01-06 08:13:49 +00:00
strcpy(pReq->app, "mnode_test_profile");
2021-12-06 06:38:37 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
2021-12-06 06:38:37 +00:00
ASSERT_NE(pMsg, nullptr);
2021-12-22 10:39:32 +00:00
ASSERT_EQ(pMsg->code, 0);
2021-12-06 06:38:37 +00:00
SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
ASSERT_NE(pRsp, nullptr);
pRsp->connId = htonl(pRsp->connId);
pRsp->queryId = htonl(pRsp->queryId);
pRsp->streamId = htonl(pRsp->streamId);
pRsp->totalDnodes = htonl(pRsp->totalDnodes);
pRsp->onlineDnodes = htonl(pRsp->onlineDnodes);
pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]);
EXPECT_EQ(pRsp->connId, connId);
EXPECT_EQ(pRsp->queryId, 1234);
EXPECT_EQ(pRsp->streamId, 0);
EXPECT_EQ(pRsp->totalDnodes, 1);
EXPECT_EQ(pRsp->onlineDnodes, 1);
EXPECT_EQ(pRsp->killConnection, 0);
EXPECT_EQ(pRsp->epSet.inUse, 0);
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
2022-01-11 11:41:38 +00:00
EXPECT_EQ(pRsp->epSet.port[0], 9031);
2021-12-06 06:38:37 +00:00
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
}
2022-01-14 07:54:07 +00:00
#endif
2021-12-06 06:38:37 +00:00
}
2022-01-06 08:13:49 +00:00
TEST_F(MndTestProfile, 08_KillQueryMsg_InvalidConn) {
2022-02-16 09:33:07 +00:00
SKillQueryReq killReq = {0};
2022-06-16 13:06:04 +00:00
strcpy(killReq.queryStrId, "2345:2345");
2021-12-06 06:38:37 +00:00
2022-02-16 09:33:07 +00:00
int32_t contLen = tSerializeSKillQueryReq(NULL, 0, &killReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSKillQueryReq(pReq, contLen, &killReq);
2021-12-06 06:38:37 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID);
2021-12-06 06:38:37 +00:00
}
2022-01-06 08:13:49 +00:00
TEST_F(MndTestProfile, 09_KillQueryMsg) {
2022-08-02 05:47:04 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_QUERIES, "perf_queries", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 0);
2021-12-06 07:06:29 +00:00
}