From 1c30141d3183b1fef2d22d25ba7e953d4610a882 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 13 Apr 2023 15:32:01 +0800 Subject: [PATCH 1/2] gcunter: stable TestTuner Signed-off-by: Weizhen Wang --- util/gctuner/tuner_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/util/gctuner/tuner_test.go b/util/gctuner/tuner_test.go index 397f4a621c96a..4dfdf68737499 100644 --- a/util/gctuner/tuner_test.go +++ b/util/gctuner/tuner_test.go @@ -17,6 +17,7 @@ package gctuner import ( "runtime" "testing" + "time" "github.com/stretchr/testify/require" ) @@ -37,7 +38,8 @@ func TestTuner(t *testing.T) { runtime.GC() for i := 0; i < 100; i++ { runtime.GC() - require.Equal(t, maxGCPercent.Load(), tn.getGCPercent()) + require.Eventually(t, func() bool { return maxGCPercent.Load() == tn.getGCPercent() }, + 500*time.Microsecond, 50*time.Microsecond) } // 1/4 threshold @@ -53,8 +55,10 @@ func TestTuner(t *testing.T) { runtime.GC() for i := 0; i < 100; i++ { runtime.GC() - require.GreaterOrEqual(t, tn.getGCPercent(), minGCPercent.Load()) - require.LessOrEqual(t, tn.getGCPercent(), maxGCPercent.Load()/2) + require.Eventually(t, func() bool { return tn.getGCPercent() >= minGCPercent.Load() }, + 500*time.Microsecond, 50*time.Microsecond) + require.Eventually(t, func() bool { return tn.getGCPercent() <= maxGCPercent.Load()/2 }, + 500*time.Microsecond, 50*time.Microsecond) } // 3/4 threshold @@ -62,7 +66,8 @@ func TestTuner(t *testing.T) { runtime.GC() for i := 0; i < 100; i++ { runtime.GC() - require.Equal(t, minGCPercent.Load(), tn.getGCPercent()) + require.Eventually(t, func() bool { return minGCPercent.Load() == tn.getGCPercent() }, + 500*time.Microsecond, 50*time.Microsecond) } // out of threshold @@ -70,7 +75,8 @@ func TestTuner(t *testing.T) { runtime.GC() for i := 0; i < 100; i++ { runtime.GC() - require.Equal(t, minGCPercent.Load(), tn.getGCPercent()) + require.Eventually(t, func() bool { return minGCPercent.Load() == tn.getGCPercent() }, + 500*time.Microsecond, 50*time.Microsecond) } } From f15fc7d4fa078e59ccb92b01f99f56b62e7c7bd1 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 13 Apr 2023 15:42:03 +0800 Subject: [PATCH 2/2] gcunter: stable TestTuner Signed-off-by: Weizhen Wang --- util/gctuner/tuner_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/gctuner/tuner_test.go b/util/gctuner/tuner_test.go index 4dfdf68737499..3393d323ff23d 100644 --- a/util/gctuner/tuner_test.go +++ b/util/gctuner/tuner_test.go @@ -39,7 +39,7 @@ func TestTuner(t *testing.T) { for i := 0; i < 100; i++ { runtime.GC() require.Eventually(t, func() bool { return maxGCPercent.Load() == tn.getGCPercent() }, - 500*time.Microsecond, 50*time.Microsecond) + 1*time.Second, 50*time.Microsecond) } // 1/4 threshold @@ -56,9 +56,9 @@ func TestTuner(t *testing.T) { for i := 0; i < 100; i++ { runtime.GC() require.Eventually(t, func() bool { return tn.getGCPercent() >= minGCPercent.Load() }, - 500*time.Microsecond, 50*time.Microsecond) + 1*time.Second, 50*time.Microsecond) require.Eventually(t, func() bool { return tn.getGCPercent() <= maxGCPercent.Load()/2 }, - 500*time.Microsecond, 50*time.Microsecond) + 1*time.Second, 50*time.Microsecond) } // 3/4 threshold @@ -67,7 +67,7 @@ func TestTuner(t *testing.T) { for i := 0; i < 100; i++ { runtime.GC() require.Eventually(t, func() bool { return minGCPercent.Load() == tn.getGCPercent() }, - 500*time.Microsecond, 50*time.Microsecond) + 1*time.Second, 50*time.Microsecond) } // out of threshold @@ -76,7 +76,7 @@ func TestTuner(t *testing.T) { for i := 0; i < 100; i++ { runtime.GC() require.Eventually(t, func() bool { return minGCPercent.Load() == tn.getGCPercent() }, - 500*time.Microsecond, 50*time.Microsecond) + 1*time.Second, 50*time.Microsecond) } }