Skip to content

Commit

Permalink
gcunter: stable TestTuner (#43021)
Browse files Browse the repository at this point in the history
close #41280
  • Loading branch information
hawkingrei authored Apr 13, 2023
1 parent ee9c81e commit 0e59c9f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions util/gctuner/tuner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package gctuner
import (
"runtime"
"testing"
"time"

"github.com/stretchr/testify/require"
)
Expand All @@ -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() },
1*time.Second, 50*time.Microsecond)
}

// 1/4 threshold
Expand All @@ -53,24 +55,28 @@ 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() },
1*time.Second, 50*time.Microsecond)
require.Eventually(t, func() bool { return tn.getGCPercent() <= maxGCPercent.Load()/2 },
1*time.Second, 50*time.Microsecond)
}

// 3/4 threshold
testHeap = make([]byte, threshold/4*3)
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() },
1*time.Second, 50*time.Microsecond)
}

// out of threshold
testHeap = make([]byte, threshold+1024)
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() },
1*time.Second, 50*time.Microsecond)
}
}

Expand Down

0 comments on commit 0e59c9f

Please sign in to comment.