From f984773c25764523c8d4304bccef51e3e4ef58a2 Mon Sep 17 00:00:00 2001 From: yzq <58433399+yangzq50@users.noreply.github.com> Date: Fri, 22 Dec 2023 16:33:24 +0800 Subject: [PATCH] fix unittest --- .../storage/buffer/buffer_handle.cpp | 20 ++++++++++++++++++- src/unit_test/storage/buffer/buffer_obj.cpp | 18 ++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/unit_test/storage/buffer/buffer_handle.cpp b/src/unit_test/storage/buffer/buffer_handle.cpp index d295e3afc3..3775f69b44 100644 --- a/src/unit_test/storage/buffer/buffer_handle.cpp +++ b/src/unit_test/storage/buffer/buffer_handle.cpp @@ -20,8 +20,26 @@ import buffer_manager; import data_file_worker; import buffer_obj; import infinity_exception; +import global_resource_usage; +import infinity_context; + +class BufferHandleTest : public BaseTest { + void SetUp() override { + BaseTest::SetUp(); + system("rm -rf /tmp/infinity/log /tmp/infinity/data /tmp/infinity/wal"); + infinity::GlobalResourceUsage::Init(); + std::shared_ptr config_path = nullptr; + infinity::InfinityContext::instance().Init(config_path); + } -class BufferHandleTest : public BaseTest {}; + void TearDown() override { + infinity::InfinityContext::instance().UnInit(); + EXPECT_EQ(infinity::GlobalResourceUsage::GetObjectCount(), 0); + EXPECT_EQ(infinity::GlobalResourceUsage::GetRawMemoryCount(), 0); + infinity::GlobalResourceUsage::UnInit(); + BaseTest::TearDown(); + } +}; TEST_F(BufferHandleTest, test1) { using namespace infinity; diff --git a/src/unit_test/storage/buffer/buffer_obj.cpp b/src/unit_test/storage/buffer/buffer_obj.cpp index 8352f23453..1947e349f2 100644 --- a/src/unit_test/storage/buffer/buffer_obj.cpp +++ b/src/unit_test/storage/buffer/buffer_obj.cpp @@ -22,9 +22,25 @@ import buffer_manager; import buffer_handle; import buffer_obj; import data_file_worker; +import global_resource_usage; +import infinity_context; class BufferObjTest : public BaseTest { - void SetUp() override { system("rm -rf /tmp/infinity"); } + void SetUp() override { + BaseTest::SetUp(); + system("rm -rf /tmp/infinity/log /tmp/infinity/data /tmp/infinity/wal"); + infinity::GlobalResourceUsage::Init(); + std::shared_ptr config_path = nullptr; + infinity::InfinityContext::instance().Init(config_path); + } + + void TearDown() override { + infinity::InfinityContext::instance().UnInit(); + EXPECT_EQ(infinity::GlobalResourceUsage::GetObjectCount(), 0); + EXPECT_EQ(infinity::GlobalResourceUsage::GetRawMemoryCount(), 0); + infinity::GlobalResourceUsage::UnInit(); + BaseTest::TearDown(); + } }; // Test status transfer of buffer handle.