Skip to content

Commit

Permalink
test: Introduce ASSERT_PROFILE_EVENT (#6371)
Browse files Browse the repository at this point in the history
ref #5237
  • Loading branch information
breezewish authored Nov 27, 2022
1 parent 7c6175f commit cfbe7f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
43 changes: 22 additions & 21 deletions dbms/src/Storages/DeltaMerge/tests/gtest_segment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <DataStreams/OneBlockInputStream.h>
#include <Storages/DeltaMerge/DeltaMergeStore.h>
#include <Storages/DeltaMerge/tests/gtest_segment_test_basic.h>
#include <TestUtils/FunctionTestUtils.h>
#include <TestUtils/TiFlashTestBasic.h>
#include <common/defines.h>
#include <gtest/gtest.h>
Expand Down Expand Up @@ -1284,10 +1285,10 @@ class IsEmptyTest : public SegmentTestBasic
TEST_F(IsEmptyTest, Basic)
try
{
auto fast_count = ProfileEvents::get(ProfileEvents::DMSegmentIsEmptyFastPath);
ASSERT_TRUE(isSegmentDefinitelyEmpty(DELTA_MERGE_FIRST_SEGMENT_ID));
ASSERT_PROFILE_EVENT(ProfileEvents::DMSegmentIsEmptyFastPath, +1, {
ASSERT_TRUE(isSegmentDefinitelyEmpty(DELTA_MERGE_FIRST_SEGMENT_ID));
});
ASSERT_EQ(0, getSegmentRowNum(DELTA_MERGE_FIRST_SEGMENT_ID));
ASSERT_EQ(fast_count + 1, ProfileEvents::get(ProfileEvents::DMSegmentIsEmptyFastPath));

writeSegment(DELTA_MERGE_FIRST_SEGMENT_ID, 100, /* at */ 0);
ASSERT_FALSE(isSegmentDefinitelyEmpty(DELTA_MERGE_FIRST_SEGMENT_ID));
Expand Down Expand Up @@ -1347,17 +1348,17 @@ try

// We will consider it to be empty after compaction.
mergeSegmentDelta(DELTA_MERGE_FIRST_SEGMENT_ID);
auto fast_count = ProfileEvents::get(ProfileEvents::DMSegmentIsEmptyFastPath);
ASSERT_TRUE(isSegmentDefinitelyEmpty(DELTA_MERGE_FIRST_SEGMENT_ID));
ASSERT_PROFILE_EVENT(ProfileEvents::DMSegmentIsEmptyFastPath, +1, {
ASSERT_TRUE(isSegmentDefinitelyEmpty(DELTA_MERGE_FIRST_SEGMENT_ID));
});
ASSERT_EQ(0, getSegmentRowNum(DELTA_MERGE_FIRST_SEGMENT_ID));
ASSERT_EQ(fast_count + 1, ProfileEvents::get(ProfileEvents::DMSegmentIsEmptyFastPath));

// For empty segment, delete range will not cause it to be "not empty".
deleteRangeSegment(DELTA_MERGE_FIRST_SEGMENT_ID);
fast_count = ProfileEvents::get(ProfileEvents::DMSegmentIsEmptyFastPath);
ASSERT_TRUE(isSegmentDefinitelyEmpty(DELTA_MERGE_FIRST_SEGMENT_ID));
ASSERT_PROFILE_EVENT(ProfileEvents::DMSegmentIsEmptyFastPath, +1, {
ASSERT_TRUE(isSegmentDefinitelyEmpty(DELTA_MERGE_FIRST_SEGMENT_ID));
});
ASSERT_EQ(0, getSegmentRowNum(DELTA_MERGE_FIRST_SEGMENT_ID));
ASSERT_EQ(fast_count + 1, ProfileEvents::get(ProfileEvents::DMSegmentIsEmptyFastPath));
}
CATCH

Expand All @@ -1373,10 +1374,10 @@ try
ASSERT_EQ(100, getSegmentRowNum(DELTA_MERGE_FIRST_SEGMENT_ID));

// This is the slow path, because ColumnFileInMemory exists for both left and right segments after logical split.
auto slow_count = ProfileEvents::get(ProfileEvents::DMSegmentIsEmptySlowPath);
ASSERT_TRUE(isSegmentDefinitelyEmpty(*right_seg));
ASSERT_PROFILE_EVENT(ProfileEvents::DMSegmentIsEmptySlowPath, +1, {
ASSERT_TRUE(isSegmentDefinitelyEmpty(*right_seg));
});
ASSERT_EQ(0, getSegmentRowNum(*right_seg));
ASSERT_EQ(slow_count + 1, ProfileEvents::get(ProfileEvents::DMSegmentIsEmptySlowPath));
}
CATCH

Expand All @@ -1393,10 +1394,10 @@ try
ASSERT_EQ(100, getSegmentRowNum(DELTA_MERGE_FIRST_SEGMENT_ID));

// This is the slow path, because ColumnFileTiny exists for both left and right segments after logical split.
auto slow_count = ProfileEvents::get(ProfileEvents::DMSegmentIsEmptySlowPath);
ASSERT_TRUE(isSegmentDefinitelyEmpty(*right_seg));
ASSERT_PROFILE_EVENT(ProfileEvents::DMSegmentIsEmptySlowPath, +1, {
ASSERT_TRUE(isSegmentDefinitelyEmpty(*right_seg));
});
ASSERT_EQ(0, getSegmentRowNum(*right_seg));
ASSERT_EQ(slow_count + 1, ProfileEvents::get(ProfileEvents::DMSegmentIsEmptySlowPath));
}
CATCH

Expand All @@ -1414,10 +1415,10 @@ try
ASSERT_EQ(100, getSegmentRowNum(DELTA_MERGE_FIRST_SEGMENT_ID));

// This goes into the fast path thanks to pack filter.
auto fast_count = ProfileEvents::get(ProfileEvents::DMSegmentIsEmptyFastPath);
ASSERT_TRUE(isSegmentDefinitelyEmpty(*right_seg));
ASSERT_PROFILE_EVENT(ProfileEvents::DMSegmentIsEmptyFastPath, +1, {
ASSERT_TRUE(isSegmentDefinitelyEmpty(*right_seg));
});
ASSERT_EQ(0, getSegmentRowNum(*right_seg));
ASSERT_EQ(fast_count + 1, ProfileEvents::get(ProfileEvents::DMSegmentIsEmptyFastPath));
}
CATCH

Expand All @@ -1439,10 +1440,10 @@ try
ASSERT_EQ(100, getSegmentRowNum(DELTA_MERGE_FIRST_SEGMENT_ID));

// This is the slow path, because pack filter will not work.
auto slow_count = ProfileEvents::get(ProfileEvents::DMSegmentIsEmptySlowPath);
ASSERT_TRUE(isSegmentDefinitelyEmpty(*seg_2));
ASSERT_PROFILE_EVENT(ProfileEvents::DMSegmentIsEmptySlowPath, +1, {
ASSERT_TRUE(isSegmentDefinitelyEmpty(*seg_2));
});
ASSERT_EQ(0, getSegmentRowNum(*seg_2));
ASSERT_EQ(slow_count + 1, ProfileEvents::get(ProfileEvents::DMSegmentIsEmptySlowPath));

ASSERT_FALSE(isSegmentDefinitelyEmpty(*seg_3));
ASSERT_EQ(42, getSegmentRowNum(*seg_3));
Expand Down
10 changes: 10 additions & 0 deletions dbms/src/TestUtils/FunctionTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -841,5 +841,15 @@ class FunctionTest : public ::testing::Test
#define ASSERT_COLUMNS_EQ_R(expected, actual) ASSERT_TRUE(DB::tests::columnsEqual((expected), (actual), true))
/// unrestrictly checking columns equality, only checking data set equality
#define ASSERT_COLUMNS_EQ_UR(expected, actual) ASSERT_TRUE(DB::tests::columnsEqual((expected), (actual), false))

/// Check the profile event change after the body.
#define ASSERT_PROFILE_EVENT(event, diff_expr, ...) \
do \
{ \
auto profile_event_count = ProfileEvents::get(event); \
{__VA_ARGS__}; \
ASSERT_EQ(profile_event_count diff_expr, ProfileEvents::get(event)); \
} while (false);

} // namespace tests
} // namespace DB

0 comments on commit cfbe7f3

Please sign in to comment.