From ff86bc296ee924d23eb293fdb788080dafbe1b8b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sun, 5 Dec 2021 20:28:27 +0800 Subject: [PATCH] TD-10431 rename test file --- source/dnode/mgmt/impl/test/CMakeLists.txt | 2 +- .../test/{test01 => profile}/CMakeLists.txt | 14 +-- .../test01.cpp => profile/profile.cpp} | 93 +++++++++++-------- source/dnode/mgmt/impl/test/sut/deploy.cpp | 16 ++-- source/dnode/mgmt/impl/test/sut/deploy.h | 2 +- 5 files changed, 73 insertions(+), 54 deletions(-) rename source/dnode/mgmt/impl/test/{test01 => profile}/CMakeLists.txt (61%) rename source/dnode/mgmt/impl/test/{test01/test01.cpp => profile/profile.cpp} (50%) diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index 95ffa548b2..79ae5631c2 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(test01) \ No newline at end of file +add_subdirectory(profile) \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/test01/CMakeLists.txt b/source/dnode/mgmt/impl/test/profile/CMakeLists.txt similarity index 61% rename from source/dnode/mgmt/impl/test/test01/CMakeLists.txt rename to source/dnode/mgmt/impl/test/profile/CMakeLists.txt index 5f88e9c116..2e99a2e53d 100644 --- a/source/dnode/mgmt/impl/test/test01/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/profile/CMakeLists.txt @@ -1,20 +1,20 @@ -add_executable(dndTest01 "") +add_executable(dndTestProfile "") -target_sources(dndTest01 +target_sources(dndTestProfile PRIVATE - "test01.cpp" + "profile.cpp" "../sut/deploy.cpp" ) target_link_libraries( - dndTest01 + dndTestProfile PUBLIC dnode PUBLIC util PUBLIC os PUBLIC gtest_main ) -target_include_directories(dndTest01 +target_include_directories(dndTestProfile PUBLIC "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" @@ -24,6 +24,6 @@ target_include_directories(dndTest01 enable_testing() add_test( - NAME dndTest01 - COMMAND dndTest01 + NAME dndTestProfile + COMMAND dndTestProfile ) diff --git a/source/dnode/mgmt/impl/test/test01/test01.cpp b/source/dnode/mgmt/impl/test/profile/profile.cpp similarity index 50% rename from source/dnode/mgmt/impl/test/test01/test01.cpp rename to source/dnode/mgmt/impl/test/profile/profile.cpp index 6c440074dc..9bbb648e66 100644 --- a/source/dnode/mgmt/impl/test/test01/test01.cpp +++ b/source/dnode/mgmt/impl/test/profile/profile.cpp @@ -15,22 +15,32 @@ #include "deploy.h" -class DndTest01 : public ::testing::Test { +class DndTestProfile : public ::testing::Test { protected: - void SetUp() override { - pServer = createServer("/tmp/dndTest01"); + void SetUp() override {} + void TearDown() override {} + + static void SetUpTestSuite() { + pServer = createServer("/tmp/dndTestProfile", "localhost", 9527); pClient = createClient("root", "taosdata"); } - void TearDown() override { + + static void TearDownTestSuite() { dropServer(pServer); dropClient(pClient); } - SServer* pServer; - SClient* pClient; + static SServer* pServer; + static SClient* pClient; }; -TEST_F(DndTest01, connectMsg) { +SServer* DndTestProfile::pServer; +SClient* DndTestProfile::pClient; + +TEST_F(DndTestProfile, connectMsg_01) { + ASSERT_NE(pServer, nullptr); + ASSERT_NE(pClient, nullptr); + SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg)); pReq->pid = htonl(1234); strcpy(pReq->app, "test01"); @@ -63,33 +73,42 @@ TEST_F(DndTest01, connectMsg) { EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost"); } -// TEST_F(DndTest01, heartbeatMsg) { -// SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg)); -// pReq->connId = htonl(1); -// pReq->pid = htonl(1234); -// pReq->numOfQueries = htonl(0); -// pReq->numOfStreams = htonl(0); -// strcpy(pReq->app, "test01"); - -// SRpcMsg rpcMsg = {0}; -// rpcMsg.pCont = pReq; -// rpcMsg.contLen = sizeof(SHeartBeatMsg); -// rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT; - -// sendMsg(pClient, &rpcMsg); - -// SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pClient->pRsp; -// ASSERT(pRsp); - // pRsp->epSet.port[0] = htonl(pRsp->epSet.port[0]); - -// EXPECT_EQ(htonl(pRsp->connId), 1); -// EXPECT_GT(htonl(pRsp->queryId), 0); -// EXPECT_GT(htonl(pRsp->streamId), 1); -// EXPECT_EQ(htonl(pRsp->totalDnodes), 1); -// EXPECT_EQ(htonl(pRsp->onlineDnodes), 1); -// EXPECT_EQ(pRsp->killConnection, 0); - // EXPECT_EQ(pRsp->epSet.inUse, 0); - // EXPECT_EQ(pRsp->epSet.numOfEps, 1); - // EXPECT_EQ(pRsp->epSet.port[0], 9527); - // EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost"); -// } +TEST_F(DndTestProfile, heartbeatMsg_01) { + ASSERT_NE(pServer, nullptr); + ASSERT_NE(pClient, nullptr); + + SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg)); + pReq->connId = htonl(1); + pReq->pid = htonl(1234); + pReq->numOfQueries = htonl(0); + pReq->numOfStreams = htonl(0); + strcpy(pReq->app, "test01"); + + SRpcMsg rpcMsg = {0}; + rpcMsg.pCont = pReq; + rpcMsg.contLen = sizeof(SHeartBeatMsg); + rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT; + + sendMsg(pClient, &rpcMsg); + + SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pClient->pRsp->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, 1); + 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); + EXPECT_EQ(pRsp->epSet.port[0], 9527); + EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost"); +} diff --git a/source/dnode/mgmt/impl/test/sut/deploy.cpp b/source/dnode/mgmt/impl/test/sut/deploy.cpp index 132ce54ec6..239120aa88 100644 --- a/source/dnode/mgmt/impl/test/sut/deploy.cpp +++ b/source/dnode/mgmt/impl/test/sut/deploy.cpp @@ -15,7 +15,7 @@ #include "deploy.h" -void initLog(char *path) { +void initLog(char* path) { mDebugFlag = 207; char temp[PATH_MAX]; snprintf(temp, PATH_MAX, "%s/taosdlog", path); @@ -32,7 +32,7 @@ void* runServer(void* param) { } } -void initOption(SDnodeOpt* pOption, char *path) { +void initOption(SDnodeOpt* pOption, char* path, char* fqdn, uint16_t port) { pOption->sver = 1; pOption->numOfCores = 1; pOption->numOfSupportMnodes = 1; @@ -44,19 +44,19 @@ void initOption(SDnodeOpt* pOption, char *path) { pOption->ratioOfQueryCores = 1; pOption->maxShellConns = 1000; pOption->shellActivityTimer = 30; - pOption->serverPort = 9527; + pOption->serverPort = port; strcpy(pOption->dataDir, path); - strcpy(pOption->localEp, "localhost:9527"); - strcpy(pOption->localFqdn, "localhost"); - strcpy(pOption->firstEp, "localhost:9527"); + snprintf(pOption->localEp, TSDB_EP_LEN, "%s:&u", fqdn, port); + snprintf(pOption->localFqdn, TSDB_FQDN_LEN, "%s", fqdn); + snprintf(pOption->firstEp, TSDB_EP_LEN, "%s:&u", fqdn, port); taosRemoveDir(path); taosMkDir(path); } -SServer* createServer(char *path) { +SServer* createServer(char* path, char* fqdn, uint16_t port) { SDnodeOpt option = {0}; - initOption(&option, path); + initOption(&option, path, fqdn, port); SDnode* pDnode = dndInit(&option); ASSERT(pDnode); diff --git a/source/dnode/mgmt/impl/test/sut/deploy.h b/source/dnode/mgmt/impl/test/sut/deploy.h index 6c47b03fe7..b830c7351e 100644 --- a/source/dnode/mgmt/impl/test/sut/deploy.h +++ b/source/dnode/mgmt/impl/test/sut/deploy.h @@ -36,7 +36,7 @@ typedef struct { tsem_t sem; } SClient; -SServer* createServer(char* path); +SServer* createServer(char* path, char *fqdn, uint16_t port); void dropServer(SServer* pServer); SClient* createClient(char *user, char *pass); void dropClient(SClient* pClient); -- GitLab