未验证 提交 e0b59648 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #9585 from taosdata/feature/dnode3

test cases for trans
......@@ -37,6 +37,8 @@ class Testbase {
void Init(const char* path, int16_t port);
void Cleanup();
void Restart();
void ServerStop();
void ServerStart();
SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen);
private:
......
......@@ -21,10 +21,10 @@ class TestServer {
bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
void Stop();
void Restart();
bool DoStart();
private:
SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
bool DoStart();
private:
SDnode* pDnode;
......
......@@ -16,13 +16,13 @@
#include "base.h"
void Testbase::InitLog(const char* path) {
dDebugFlag = 207;
dDebugFlag = 0;
vDebugFlag = 0;
mDebugFlag = 207;
mDebugFlag = 143;
cDebugFlag = 0;
jniDebugFlag = 0;
tmrDebugFlag = 0;
uDebugFlag = 143;
uDebugFlag = 0;
rpcDebugFlag = 0;
qDebugFlag = 0;
wDebugFlag = 0;
......@@ -60,6 +60,10 @@ void Testbase::Cleanup() {
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 rpcMsg = {0};
rpcMsg.pCont = pCont;
......
......@@ -2,3 +2,4 @@ enable_testing()
add_subdirectory(acct)
add_subdirectory(user)
add_subdirectory(trans)
/**
* @file acct.cpp
* @author slguan (slguan@taosdata.com)
* @brief MNODE module acct-msg tests
* @version 0.1
* @brief MNODE module acct tests
* @version 1.0
* @date 2021-12-15
*
* @copyright Copyright (c) 2021
* @copyright Copyright (c) 2022
*
*/
......
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
)
/**
* @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);
}
\ No newline at end of file
/**
* @file user.cpp
* @author slguan (slguan@taosdata.com)
* @brief MNODE module user-msg tests
* @version 0.1
* @brief MNODE module user tests
* @version 1.0
* @date 2021-12-15
*
* @copyright Copyright (c) 2021
......@@ -13,7 +13,7 @@
class DndTestUser : public ::testing::Test {
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 Testbase test;
......@@ -190,7 +190,7 @@ TEST_F(DndTestUser, 04_Drop_User) {
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);
......
......@@ -231,7 +231,7 @@ int32_t sdbWriteFile(SSdb *pSdb) {
mDebug("start to write file:%s", curfile);
FileFd fd = taosOpenFileCreateWrite(tmpfile);
FileFd fd = taosOpenFileCreateWriteTrunc(tmpfile);
if (fd <= 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
mError("failed to open file:%s for write since %s", tmpfile, terrstr());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册