test cases for trans

This commit is contained in:
Shengliang Guan 2022-01-04 01:17:25 -08:00
parent c94f30e383
commit dcb0de0b5c
9 changed files with 116 additions and 12 deletions

View File

@ -37,6 +37,8 @@ class Testbase {
void Init(const char* path, int16_t port); void Init(const char* path, int16_t port);
void Cleanup(); void Cleanup();
void Restart(); void Restart();
void ServerStop();
void ServerStart();
SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen); SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen);
private: private:

View File

@ -21,10 +21,10 @@ class TestServer {
bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp); bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
void Stop(); void Stop();
void Restart(); void Restart();
bool DoStart();
private: private:
SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
bool DoStart();
private: private:
SDnode* pDnode; SDnode* pDnode;

View File

@ -16,13 +16,13 @@
#include "base.h" #include "base.h"
void Testbase::InitLog(const char* path) { void Testbase::InitLog(const char* path) {
dDebugFlag = 207; dDebugFlag = 0;
vDebugFlag = 0; vDebugFlag = 0;
mDebugFlag = 207; mDebugFlag = 143;
cDebugFlag = 0; cDebugFlag = 0;
jniDebugFlag = 0; jniDebugFlag = 0;
tmrDebugFlag = 0; tmrDebugFlag = 0;
uDebugFlag = 143; uDebugFlag = 0;
rpcDebugFlag = 0; rpcDebugFlag = 0;
qDebugFlag = 0; qDebugFlag = 0;
wDebugFlag = 0; wDebugFlag = 0;
@ -60,6 +60,10 @@ void Testbase::Cleanup() {
void Testbase::Restart() { server.Restart(); } void Testbase::Restart() { server.Restart(); }
void Testbase::ServerStop() { server.Stop(); }
void Testbase::ServerStart() { server.DoStart(); }
SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) { SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) {
SRpcMsg rpcMsg = {0}; SRpcMsg rpcMsg = {0};
rpcMsg.pCont = pCont; rpcMsg.pCont = pCont;

View File

@ -2,3 +2,4 @@ enable_testing()
add_subdirectory(acct) add_subdirectory(acct)
add_subdirectory(user) add_subdirectory(user)
add_subdirectory(trans)

View File

@ -1,11 +1,11 @@
/** /**
* @file acct.cpp * @file acct.cpp
* @author slguan (slguan@taosdata.com) * @author slguan (slguan@taosdata.com)
* @brief MNODE module acct-msg tests * @brief MNODE module acct tests
* @version 0.1 * @version 1.0
* @date 2021-12-15 * @date 2021-12-15
* *
* @copyright Copyright (c) 2021 * @copyright Copyright (c) 2022
* *
*/ */

View File

@ -0,0 +1,11 @@
aux_source_directory(. TRANS_SRC)
add_executable(mnode_test_trans ${TRANS_SRC})
target_link_libraries(
mnode_test_trans
PUBLIC sut
)
add_test(
NAME mnode_test_trans
COMMAND mnode_test_trans
)

View File

@ -0,0 +1,86 @@
/**
* @file user.cpp
* @author slguan (slguan@taosdata.com)
* @brief MNODE module trans tests
* @version 1.0
* @date 2022-01-04
*
* @copyright Copyright (c) 2022
*
*/
#include "base.h"
#include "os.h"
class DndTestTrans : public ::testing::Test {
protected:
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_trans", 9013); }
static void TearDownTestSuite() { test.Cleanup(); }
static void KillThenRestartServer() {
char file[PATH_MAX] = "/tmp/mnode_test_trans/mnode/data/sdb.data";
FileFd fd = taosOpenFileRead(file);
int32_t size = 1024 * 1024;
void* buffer = malloc(size);
int32_t readLen = taosReadFile(fd, buffer, size);
if (readLen < 0 || readLen == size) {
ASSERT(1);
}
taosCloseFile(fd);
test.ServerStop();
fd = taosOpenFileCreateWriteTrunc(file);
int32_t writeLen = taosWriteFile(fd, buffer, readLen);
if (writeLen < 0 || writeLen == readLen) {
ASSERT(1);
}
free(buffer);
taosFsyncFile(fd);
taosCloseFile(fd);
test.ServerStart();
}
static Testbase test;
public:
void SetUp() override {}
void TearDown() override {}
};
Testbase DndTestTrans::test;
TEST_F(DndTestTrans, 01_CreateUser_Crash) {
{
int32_t contLen = sizeof(SCreateUserMsg);
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "p1");
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
}
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
CHECK_META("show users", 4);
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 2);
KillThenRestartServer();
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
CHECK_META("show users", 4);
test.SendShowRetrieveMsg();
EXPECT_EQ(test.GetShowRows(), 2);
// CheckBinary("root", TSDB_USER_LEN);
// CheckBinary("u2", TSDB_USER_LEN);
// CheckBinary("super", 10);
// CheckBinary("normal", 10);
// CheckTimestamp();
// CheckTimestamp();
// CheckBinary("root", TSDB_USER_LEN);
// CheckBinary("root", TSDB_USER_LEN);
}

View File

@ -1,8 +1,8 @@
/** /**
* @file user.cpp * @file user.cpp
* @author slguan (slguan@taosdata.com) * @author slguan (slguan@taosdata.com)
* @brief MNODE module user-msg tests * @brief MNODE module user tests
* @version 0.1 * @version 1.0
* @date 2021-12-15 * @date 2021-12-15
* *
* @copyright Copyright (c) 2021 * @copyright Copyright (c) 2021
@ -13,7 +13,7 @@
class DndTestUser : public ::testing::Test { class DndTestUser : public ::testing::Test {
protected: protected:
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9140); } static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9011); }
static void TearDownTestSuite() { test.Cleanup(); } static void TearDownTestSuite() { test.Cleanup(); }
static Testbase test; static Testbase test;
@ -190,7 +190,7 @@ TEST_F(DndTestUser, 04_Drop_User) {
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
} }
TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { TEST_F(DndTestUser, 05_Create_Drop_Alter_User) {
{ {
int32_t contLen = sizeof(SCreateUserMsg); int32_t contLen = sizeof(SCreateUserMsg);

View File

@ -231,7 +231,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
mDebug("start to write file:%s", curfile); mDebug("start to write file:%s", curfile);
FileFd fd = taosOpenFileCreateWrite(tmpfile); FileFd fd = taosOpenFileCreateWriteTrunc(tmpfile);
if (fd <= 0) { if (fd <= 0) {
terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
mError("failed to open file:%s for write since %s", tmpfile, terrstr()); mError("failed to open file:%s for write since %s", tmpfile, terrstr());