Skip to content

Commit

Permalink
gogctuner: fix unstable test in the TestTuner (#39101)
Browse files Browse the repository at this point in the history
close #38467
  • Loading branch information
hawkingrei authored Nov 14, 2022
1 parent e939c9b commit 61b02ec
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions util/gctuner/tuner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var testHeap []byte

func TestTuner(t *testing.T) {
EnableGOGCTuner.Store(true)
memLimit := uint64(100 * 1024 * 1024) //100 MB
memLimit := uint64(1000 * 1024 * 1024) //1000 MB
threshold := memLimit / 2
tn := newTuner(threshold)
require.Equal(t, threshold, tn.threshold.Load())
Expand All @@ -44,17 +44,17 @@ func TestTuner(t *testing.T) {
testHeap = make([]byte, threshold/4)
for i := 0; i < 100; i++ {
runtime.GC()
require.GreaterOrEqual(t, tn.getGCPercent(), uint32(100))
require.LessOrEqual(t, tn.getGCPercent(), uint32(500))
require.GreaterOrEqual(t, tn.getGCPercent(), MaxGCPercent/2)
require.LessOrEqual(t, tn.getGCPercent(), MaxGCPercent)
}

// 1/2 threshold
testHeap = make([]byte, threshold/2)
runtime.GC()
for i := 0; i < 100; i++ {
runtime.GC()
require.GreaterOrEqual(t, tn.getGCPercent(), uint32(50))
require.LessOrEqual(t, tn.getGCPercent(), uint32(100))
require.GreaterOrEqual(t, tn.getGCPercent(), MinGCPercent)
require.LessOrEqual(t, tn.getGCPercent(), MaxGCPercent/2)
}

// 3/4 threshold
Expand Down

0 comments on commit 61b02ec

Please sign in to comment.