diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/base.h index 41382fbab5cdfba3f14417e51ba7cef3ed0a8dad..24278a73f7c2a07ccfb68fd5f096df6559338e7b 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/base.h +++ b/source/dnode/mgmt/impl/test/sut/inc/base.h @@ -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: diff --git a/source/dnode/mgmt/impl/test/sut/inc/server.h b/source/dnode/mgmt/impl/test/sut/inc/server.h index aa7b37f22118ca0ca4081235624903dc010f85af..5f9e4846a7063826d89ed217833afdd4a55095cc 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/server.h +++ b/source/dnode/mgmt/impl/test/sut/inc/server.h @@ -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; diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/base.cpp index 429d5a6976b02cc8c4344b149703f7cd3f44497f..e1b6664e9fcfa2f59be737cbef6752c96976a7d1 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/base.cpp @@ -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; diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index fa7b45f988c4b12f19135781d2b3cc505e19df45..dfac7a76c93082800eba7ff12b1943322cf3530b 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -2,3 +2,4 @@ enable_testing() add_subdirectory(acct) add_subdirectory(user) +add_subdirectory(trans) diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 934a2d96b4ab6c3d1781277c118913314984efe0..5f105d99f3b272984c02bca503ccc9c8d29e27fa 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -1,11 +1,11 @@ /** * @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 * */ diff --git a/source/dnode/mnode/impl/test/trans/CMakeLists.txt b/source/dnode/mnode/impl/test/trans/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7c9756794f810828fe4e7503e57f9b705169959 --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/CMakeLists.txt @@ -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 +) diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1400ad897f281cc3927f8432583f4ce4918d880a --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -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); +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index ad2e38e0a4a1ca94313138ff1106a06614b1566b..536150ccfddb3a0f6e955aa177b059e4172ca3ba 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -1,8 +1,8 @@ /** * @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); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 970fdc2061d8c85a36dd7970c81810cc494d02b5..1f6d6cbda8f4976b7e03569f0b5f39a362e0d7ca 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -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());