Skip to content

Commit

Permalink
fix: force read ut memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Abingcbc committed Dec 3, 2024
1 parent 5707547 commit 81319b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions core/unittest/reader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
18 changes: 13 additions & 5 deletions core/unittest/reader/ForceReadUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
#include <memory>
#include <string>

#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"
Expand Down Expand Up @@ -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<char[]> expectedContent;
Expand Down Expand Up @@ -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<ModifyHandler>(mConfigName, mConfig);
pHanlder->mReadFileTimeSlice = 0; // force one read for one event
Expand Down

0 comments on commit 81319b0

Please sign in to comment.