Skip to content

Commit

Permalink
fix event pool unittest memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
henryzhx8 committed Dec 16, 2024
1 parent 7695ae8 commit 02bfe24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/unittest/models/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ target_link_libraries(pipeline_event_ptr_unittest ${UT_BASE_TARGET})
add_executable(pipeline_event_group_unittest PipelineEventGroupUnittest.cpp)
target_link_libraries(pipeline_event_group_unittest ${UT_BASE_TARGET})

# add_executable(event_pool_unittest EventPoolUnittest.cpp)
# target_link_libraries(event_pool_unittest ${UT_BASE_TARGET})
add_executable(event_pool_unittest EventPoolUnittest.cpp)
target_link_libraries(event_pool_unittest ${UT_BASE_TARGET})

include(GoogleTest)
gtest_discover_tests(pipeline_event_unittest)
Expand All @@ -51,7 +51,7 @@ gtest_discover_tests(span_event_unittest)
gtest_discover_tests(raw_event_unittest)
gtest_discover_tests(pipeline_event_ptr_unittest)
gtest_discover_tests(pipeline_event_group_unittest)
# gtest_discover_tests(event_pool_unittest)
gtest_discover_tests(event_pool_unittest)

add_executable(event_group_benchmark EventGroupBenchmark.cpp)
target_link_libraries(event_group_benchmark ${UT_BASE_TARGET})
19 changes: 15 additions & 4 deletions core/unittest/models/EventPoolUnittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void EventPoolUnittest::TestNoLock() {
APSARA_TEST_EQUAL(0U, pool.mLogEventPool.size());
APSARA_TEST_EQUAL(0U, pool.mMinUnusedLogEventsCnt);
APSARA_TEST_EQUAL(&g, e->GetPipelineEventGroupPtr());
delete e;
}
{
auto e = pool.AcquireMetricEvent(mGroup.get());
Expand All @@ -61,6 +62,7 @@ void EventPoolUnittest::TestNoLock() {
APSARA_TEST_EQUAL(0U, pool.mMetricEventPool.size());
APSARA_TEST_EQUAL(0U, pool.mMinUnusedMetricEventsCnt);
APSARA_TEST_EQUAL(&g, e->GetPipelineEventGroupPtr());
delete e;
}
{
auto e = pool.AcquireSpanEvent(mGroup.get());
Expand All @@ -74,6 +76,7 @@ void EventPoolUnittest::TestNoLock() {
APSARA_TEST_EQUAL(0U, pool.mSpanEventPool.size());
APSARA_TEST_EQUAL(0U, pool.mMinUnusedSpanEventsCnt);
APSARA_TEST_EQUAL(&g, e->GetPipelineEventGroupPtr());
delete e;
}
{
auto e = pool.AcquireRawEvent(mGroup.get());
Expand All @@ -87,7 +90,9 @@ void EventPoolUnittest::TestNoLock() {
APSARA_TEST_EQUAL(0U, pool.mRawEventPool.size());
APSARA_TEST_EQUAL(0U, pool.mMinUnusedRawEventsCnt);
APSARA_TEST_EQUAL(&g, e->GetPipelineEventGroupPtr());
delete e;
}
pool.Clear();
}

void EventPoolUnittest::TestLock() {
Expand All @@ -107,9 +112,11 @@ void EventPoolUnittest::TestLock() {
APSARA_TEST_EQUAL(mGroup.get(), e->GetPipelineEventGroupPtr());

pool.Release(vector<LogEvent*>{e, e1});
pool.AcquireLogEvent(mGroup.get());
auto e2 = pool.AcquireLogEvent(mGroup.get());
APSARA_TEST_EQUAL(0U, pool.mLogEventPoolBak.size());
APSARA_TEST_EQUAL(1U, pool.mLogEventPool.size());
delete e2;

}
{
auto e = pool.AcquireMetricEvent(mGroup.get());
Expand All @@ -125,9 +132,10 @@ void EventPoolUnittest::TestLock() {
APSARA_TEST_EQUAL(mGroup.get(), e->GetPipelineEventGroupPtr());

pool.Release(vector<MetricEvent*>{e, e1});
pool.AcquireMetricEvent(mGroup.get());
auto e2 = pool.AcquireMetricEvent(mGroup.get());
APSARA_TEST_EQUAL(0U, pool.mMetricEventPoolBak.size());
APSARA_TEST_EQUAL(1U, pool.mMetricEventPool.size());
delete e2;
}
{
auto e = pool.AcquireSpanEvent(mGroup.get());
Expand All @@ -143,9 +151,10 @@ void EventPoolUnittest::TestLock() {
APSARA_TEST_EQUAL(mGroup.get(), e->GetPipelineEventGroupPtr());

pool.Release(vector<SpanEvent*>{e, e1});
pool.AcquireSpanEvent(mGroup.get());
auto e2 = pool.AcquireSpanEvent(mGroup.get());
APSARA_TEST_EQUAL(0U, pool.mSpanEventPoolBak.size());
APSARA_TEST_EQUAL(1U, pool.mSpanEventPool.size());
delete e2;
}
{
auto e = pool.AcquireRawEvent(mGroup.get());
Expand All @@ -161,10 +170,12 @@ void EventPoolUnittest::TestLock() {
APSARA_TEST_EQUAL(mGroup.get(), e->GetPipelineEventGroupPtr());

pool.Release(vector<RawEvent*>{e, e1});
pool.AcquireRawEvent(mGroup.get());
auto e2 = pool.AcquireRawEvent(mGroup.get());
APSARA_TEST_EQUAL(0U, pool.mRawEventPoolBak.size());
APSARA_TEST_EQUAL(1U, pool.mRawEventPool.size());
delete e2;
}
pool.Clear();
}

void EventPoolUnittest::TestGC() {
Expand Down

0 comments on commit 02bfe24

Please sign in to comment.