From 81319b0967af15c46140fb00c50b7423778f9665 Mon Sep 17 00:00:00 2001 From: abingcbc Date: Tue, 3 Dec 2024 09:33:34 +0800 Subject: [PATCH] fix: force read ut memory leak --- core/unittest/reader/CMakeLists.txt | 6 +++--- core/unittest/reader/ForceReadUnittest.cpp | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/core/unittest/reader/CMakeLists.txt b/core/unittest/reader/CMakeLists.txt index 80df50da23..f870f9adfd 100644 --- a/core/unittest/reader/CMakeLists.txt +++ b/core/unittest/reader/CMakeLists.txt @@ -36,8 +36,8 @@ target_link_libraries(source_buffer_unittest ${UT_BASE_TARGET}) add_executable(get_last_line_data_unittest GetLastLineDataUnittest.cpp) target_link_libraries(get_last_line_data_unittest ${UT_BASE_TARGET}) -# add_executable(force_read_unittest ForceReadUnittest.cpp) -# target_link_libraries(force_read_unittest ${UT_BASE_TARGET}) +add_executable(force_read_unittest ForceReadUnittest.cpp) +target_link_libraries(force_read_unittest ${UT_BASE_TARGET}) if (UNIX) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/testDataSet) @@ -55,4 +55,4 @@ gtest_discover_tests(remove_last_incomplete_log_unittest) gtest_discover_tests(log_file_reader_unittest) gtest_discover_tests(source_buffer_unittest) gtest_discover_tests(get_last_line_data_unittest) -# gtest_discover_tests(force_read_unittest) +gtest_discover_tests(force_read_unittest) diff --git a/core/unittest/reader/ForceReadUnittest.cpp b/core/unittest/reader/ForceReadUnittest.cpp index db306614ad..a14e4bf6cc 100644 --- a/core/unittest/reader/ForceReadUnittest.cpp +++ b/core/unittest/reader/ForceReadUnittest.cpp @@ -19,16 +19,16 @@ #include #include -#include "constants/Constants.h" #include "common/FileSystemUtil.h" #include "common/Flags.h" #include "common/JsonUtil.h" #include "config/PipelineConfig.h" +#include "constants/Constants.h" #include "file_server/ConfigManager.h" +#include "file_server/FileServer.h" #include "file_server/event/BlockEventManager.h" #include "file_server/event/Event.h" #include "file_server/event_handler/EventHandler.h" -#include "file_server/FileServer.h" #include "logger/Logger.h" #include "pipeline/Pipeline.h" #include "pipeline/queue/ProcessQueueManager.h" @@ -119,7 +119,17 @@ class ForceReadUnittest : public testing::Test { ProcessQueueManager::GetInstance()->EnablePop(mConfigName); } - void TearDown() override { remove(utf8File.c_str()); } + void TearDown() override { + remove(utf8File.c_str()); + for (auto iter = BlockedEventManager::GetInstance()->mEventMap.begin(); + iter != BlockedEventManager::GetInstance()->mEventMap.end(); + ++iter) { + if (iter->second.mEvent != nullptr) { + delete iter->second.mEvent; + } + } + BlockedEventManager::GetInstance()->mEventMap.clear(); + } private: std::unique_ptr expectedContent; @@ -345,8 +355,6 @@ void ForceReadUnittest::TestAddTimeoutEvent() { reader.InitReader(true, LogFileReader::BACKWARD_TO_BEGINNING); reader.CheckFileSignatureAndOffset(true); LogFileReader::BUFFER_SIZE = 10; - BlockedEventManager::GetInstance()->mEventMap.clear(); - APSARA_TEST_EQUAL_FATAL(BlockedEventManager::GetInstance()->mEventMap.size(), 0U); auto pHanlder = make_unique(mConfigName, mConfig); pHanlder->mReadFileTimeSlice = 0; // force one read for one event