From 0bfbdc32071e5feb6c5615c1209c42e64d42fb0d Mon Sep 17 00:00:00 2001 From: disksing Date: Tue, 23 Jul 2024 17:46:34 +0800 Subject: [PATCH] gctuner: check intest flag in tests (#54837) close pingcap/tidb#54836 --- pkg/util/gctuner/BUILD.bazel | 1 + pkg/util/gctuner/finalizer_test.go | 2 ++ pkg/util/gctuner/memory_limit_tuner_test.go | 3 +++ pkg/util/gctuner/tuner_test.go | 3 +++ 4 files changed, 9 insertions(+) diff --git a/pkg/util/gctuner/BUILD.bazel b/pkg/util/gctuner/BUILD.bazel index 0052b084a1c65..16de85d2c84f0 100644 --- a/pkg/util/gctuner/BUILD.bazel +++ b/pkg/util/gctuner/BUILD.bazel @@ -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", diff --git a/pkg/util/gctuner/finalizer_test.go b/pkg/util/gctuner/finalizer_test.go index 1a86a887d6410..8c641c06c7882 100644 --- a/pkg/util/gctuner/finalizer_test.go +++ b/pkg/util/gctuner/finalizer_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/pingcap/tidb/pkg/util/intest" "github.com/stretchr/testify/require" ) @@ -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{} diff --git a/pkg/util/gctuner/memory_limit_tuner_test.go b/pkg/util/gctuner/memory_limit_tuner_test.go index 422515c214e0e..9b71cc2cdab5e 100644 --- a/pkg/util/gctuner/memory_limit_tuner_test.go +++ b/pkg/util/gctuner/memory_limit_tuner_test.go @@ -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" ) @@ -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")) @@ -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) diff --git a/pkg/util/gctuner/tuner_test.go b/pkg/util/gctuner/tuner_test.go index 89772fcca9f4e..2ee5fef1a318b 100644 --- a/pkg/util/gctuner/tuner_test.go +++ b/pkg/util/gctuner/tuner_test.go @@ -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 @@ -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))