Skip to content

Commit

Permalink
statistics: do not need to introduce another test flag (pingcap#50813)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 authored Jan 30, 2024
1 parent fdb13d1 commit 556c0d4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
6 changes: 2 additions & 4 deletions pkg/statistics/handle/cache/internal/lfu/lfu_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ type LFU struct {
closeOnce sync.Once
}

var testMode = false

// NewLFU creates a new LFU cache.
func NewLFU(totalMemCost int64) (*LFU, error) {
cost, err := adjustMemCost(totalMemCost)
Expand All @@ -64,8 +62,8 @@ func NewLFU(totalMemCost int64) (*LFU, error) {
OnEvict: result.onEvict,
OnExit: result.onExit,
OnReject: result.onReject,
IgnoreInternalCost: testMode,
Metrics: testMode,
IgnoreInternalCost: intest.InTest,
Metrics: intest.InTest,
},
)
if err != nil {
Expand Down
13 changes: 1 addition & 12 deletions pkg/statistics/handle/cache/internal/lfu/lfu_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ import (
)

var (
mockCMSMemoryUsage = int64(4)
mockTopNMemoryUsage = int64(64)
mockHistMemoryUsage = int64(289)
mockCMSMemoryUsage = int64(4)
)

func TestLFUPutGetDel(t *testing.T) {
testMode = true
capacity := int64(100)
lfu, err := NewLFU(capacity)
require.NoError(t, err)
Expand All @@ -50,7 +47,6 @@ func TestLFUPutGetDel(t *testing.T) {
}

func TestLFUFreshMemUsage(t *testing.T) {
testMode = true
lfu, err := NewLFU(10000)
require.NoError(t, err)
t1 := testutil.NewMockStatisticsTable(1, 1, true, false, false)
Expand Down Expand Up @@ -85,7 +81,6 @@ func TestLFUFreshMemUsage(t *testing.T) {
}

func TestLFUPutTooBig(t *testing.T) {
testMode = true
lfu, err := NewLFU(1)
require.NoError(t, err)
mockTable := testutil.NewMockStatisticsTable(1, 1, true, false, false)
Expand All @@ -98,7 +93,6 @@ func TestLFUPutTooBig(t *testing.T) {
}

func TestCacheLen(t *testing.T) {
testMode = true
capacity := int64(12)
lfu, err := NewLFU(capacity)
require.NoError(t, err)
Expand All @@ -121,7 +115,6 @@ func TestCacheLen(t *testing.T) {
}

func TestLFUCachePutGetWithManyConcurrency(t *testing.T) {
testMode = true
// to test DATA RACE
capacity := int64(100000000000)
lfu, err := NewLFU(capacity)
Expand All @@ -147,7 +140,6 @@ func TestLFUCachePutGetWithManyConcurrency(t *testing.T) {
}

func TestLFUCachePutGetWithManyConcurrency2(t *testing.T) {
testMode = true
// to test DATA RACE
capacity := int64(100000000000)
lfu, err := NewLFU(capacity)
Expand Down Expand Up @@ -178,7 +170,6 @@ func TestLFUCachePutGetWithManyConcurrency2(t *testing.T) {
}

func TestLFUCachePutGetWithManyConcurrencyAndSmallConcurrency(t *testing.T) {
testMode = true
// to test DATA RACE

capacity := int64(100)
Expand Down Expand Up @@ -244,7 +235,6 @@ func checkTable(t *testing.T, tbl *statistics.Table) {
}

func TestLFUReject(t *testing.T) {
testMode = true
capacity := int64(100000000000)
lfu, err := NewLFU(capacity)
require.NoError(t, err)
Expand Down Expand Up @@ -273,7 +263,6 @@ func TestLFUReject(t *testing.T) {
}

func TestMemoryControl(t *testing.T) {
testMode = true
capacity := int64(100000000000)
lfu, err := NewLFU(capacity)
require.NoError(t, err)
Expand Down

0 comments on commit 556c0d4

Please sign in to comment.