Skip to content

Commit

Permalink
gctuner: check intest flag in tests (#54837)
Browse files Browse the repository at this point in the history
close #54836
  • Loading branch information
disksing authored Jul 23, 2024
1 parent 419139e commit 0bfbdc3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/util/gctuner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ go_test(
race = "on",
shard_count = 5,
deps = [
"//pkg/util/intest",
"//pkg/util/memory",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/gctuner/finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"testing"
"time"

"github.com/pingcap/tidb/pkg/util/intest"
"github.com/stretchr/testify/require"
)

Expand All @@ -29,6 +30,7 @@ type testState struct {
}

func TestFinalizer(t *testing.T) {
require.True(t, intest.InTest)
debug.SetGCPercent(1000)
maxCount := int32(8)
state := &testState{}
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/gctuner/memory_limit_tuner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/util/intest"
"github.com/pingcap/tidb/pkg/util/memory"
"github.com/stretchr/testify/require"
)
Expand All @@ -45,6 +46,7 @@ func (a *mockAllocator) freeAll() {
}

func TestGlobalMemoryTuner(t *testing.T) {
require.True(t, intest.InTest)
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/util/gctuner/testMemoryLimitTuner", "return(true)"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/util/gctuner/testMemoryLimitTuner"))
Expand Down Expand Up @@ -125,6 +127,7 @@ func TestGlobalMemoryTuner(t *testing.T) {
}

func TestIssue48741(t *testing.T) {
require.True(t, intest.InTest)
// Close GOGCTuner
gogcTuner := EnableGOGCTuner.Load()
EnableGOGCTuner.Store(false)
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/gctuner/tuner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ import (
"runtime"
"testing"

"github.com/pingcap/tidb/pkg/util/intest"
"github.com/stretchr/testify/require"
)

var testHeap []byte

func TestTuner(t *testing.T) {
require.True(t, intest.InTest)
EnableGOGCTuner.Store(true)
memLimit := uint64(1000 * 1024 * 1024) //1000 MB
threshold := memLimit / 2
Expand Down Expand Up @@ -93,6 +95,7 @@ func TestTuner(t *testing.T) {
}

func TestCalcGCPercent(t *testing.T) {
require.True(t, intest.InTest)
const gb = 1024 * 1024 * 1024
// use default value when invalid params
require.Equal(t, defaultGCPercent, calcGCPercent(0, 0))
Expand Down

0 comments on commit 0bfbdc3

Please sign in to comment.