diff --git a/pkg/cgroup/cgroup_cpu_test.go b/pkg/cgroup/cgroup_cpu_test.go index e678a79a0a4..fad947632de 100644 --- a/pkg/cgroup/cgroup_cpu_test.go +++ b/pkg/cgroup/cgroup_cpu_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build linux +//go:build linux && enable_flaky_tests package cgroup diff --git a/pkg/gctuner/finalizer_test.go b/pkg/gctuner/finalizer_test.go index c3f74936326..64cb308d931 100644 --- a/pkg/gctuner/finalizer_test.go +++ b/pkg/gctuner/finalizer_test.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build enable_flaky_tests + package gctuner import ( diff --git a/pkg/gctuner/memory_limit_tuner_test.go b/pkg/gctuner/memory_limit_tuner_test.go index 7c7a1552bcc..f56a64a7326 100644 --- a/pkg/gctuner/memory_limit_tuner_test.go +++ b/pkg/gctuner/memory_limit_tuner_test.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build enable_flaky_tests + package gctuner import ( diff --git a/pkg/gctuner/tuner_calc_test.go b/pkg/gctuner/tuner_calc_test.go new file mode 100644 index 00000000000..473f5bda67d --- /dev/null +++ b/pkg/gctuner/tuner_calc_test.go @@ -0,0 +1,39 @@ +// Copyright 2023 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gctuner + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCalcGCPercent(t *testing.T) { + const gb = 1024 * 1024 * 1024 + // use default value when invalid params + require.Equal(t, defaultGCPercent, calcGCPercent(0, 0)) + require.Equal(t, defaultGCPercent, calcGCPercent(0, 1)) + require.Equal(t, defaultGCPercent, calcGCPercent(1, 0)) + + require.Equal(t, maxGCPercent.Load(), calcGCPercent(1, 3*gb)) + require.Equal(t, maxGCPercent.Load(), calcGCPercent(gb/10, 4*gb)) + require.Equal(t, maxGCPercent.Load(), calcGCPercent(gb/2, 4*gb)) + require.Equal(t, uint32(300), calcGCPercent(1*gb, 4*gb)) + require.Equal(t, uint32(166), calcGCPercent(1.5*gb, 4*gb)) + require.Equal(t, uint32(100), calcGCPercent(2*gb, 4*gb)) + require.Equal(t, uint32(100), calcGCPercent(3*gb, 4*gb)) + require.Equal(t, minGCPercent.Load(), calcGCPercent(4*gb, 4*gb)) + require.Equal(t, minGCPercent.Load(), calcGCPercent(5*gb, 4*gb)) +} diff --git a/pkg/gctuner/tuner_test.go b/pkg/gctuner/tuner_test.go index e8ac5736088..604cd449b35 100644 --- a/pkg/gctuner/tuner_test.go +++ b/pkg/gctuner/tuner_test.go @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//go:build enable_flaky_tests + package gctuner import ( @@ -73,21 +75,3 @@ func TestTuner(t *testing.T) { require.Equal(t, minGCPercent.Load(), tn.getGCPercent()) } } - -func TestCalcGCPercent(t *testing.T) { - const gb = 1024 * 1024 * 1024 - // use default value when invalid params - require.Equal(t, defaultGCPercent, calcGCPercent(0, 0)) - require.Equal(t, defaultGCPercent, calcGCPercent(0, 1)) - require.Equal(t, defaultGCPercent, calcGCPercent(1, 0)) - - require.Equal(t, maxGCPercent.Load(), calcGCPercent(1, 3*gb)) - require.Equal(t, maxGCPercent.Load(), calcGCPercent(gb/10, 4*gb)) - require.Equal(t, maxGCPercent.Load(), calcGCPercent(gb/2, 4*gb)) - require.Equal(t, uint32(300), calcGCPercent(1*gb, 4*gb)) - require.Equal(t, uint32(166), calcGCPercent(1.5*gb, 4*gb)) - require.Equal(t, uint32(100), calcGCPercent(2*gb, 4*gb)) - require.Equal(t, uint32(100), calcGCPercent(3*gb, 4*gb)) - require.Equal(t, minGCPercent.Load(), calcGCPercent(4*gb, 4*gb)) - require.Equal(t, minGCPercent.Load(), calcGCPercent(5*gb, 4*gb)) -}