-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgc_tuner_test.go
68 lines (63 loc) · 1.68 KB
/
gc_tuner_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package gogctuner
import (
"math"
"testing"
)
// func getGOGC(previousGOGC int , memoryLimitInPercent, memPercent float64) int {
type GetGOGCTestCase struct {
MemoryLimitInPercent float64
TotalSize uint64
LiveSize float64
ExpectedGOGC int
}
func TestGetGOGCBasics(t *testing.T) {
cases := []GetGOGCTestCase{
{
MemoryLimitInPercent: 40,
TotalSize: 10000,
LiveSize: 6000,
ExpectedGOGC: int(math.Max(58, minGOGCValue)),
},
{
MemoryLimitInPercent: 40,
TotalSize: 10000,
LiveSize: 9000,
ExpectedGOGC: minGOGCValue,
},
{
MemoryLimitInPercent: 80,
TotalSize: 10000,
LiveSize: 1000,
ExpectedGOGC: 700,
},
{
MemoryLimitInPercent: 80,
TotalSize: 10000,
LiveSize: 3000,
ExpectedGOGC: 166,
},
}
for i, _ := range cases {
result := getGOGC(cases[i].MemoryLimitInPercent, cases[i].TotalSize, cases[i].LiveSize, goGCNoLimit)
if result != cases[i].ExpectedGOGC {
t.Errorf("Failed Test Case #%v - Expected: %v Found: %v", i+1, cases[i].ExpectedGOGC, result)
}
}
}
func TestGcConfig(t *testing.T) {
testGcConfigCheck(t, 0, true)
testGcConfigCheck(t, 90, true)
testGcConfigCheck(t, 100, true)
testGcConfigCheck(t, 101, false)
testGcConfigCheck(t, -1, false)
}
func testGcConfigCheck(t *testing.T, maxRamPercentage float64, expectValid bool) {
config := Config{MaxRAMPercentage: maxRamPercentage}
expect := "invalid"
if expectValid {
expect = "valid"
}
if config.CheckValid() == nil != expectValid {
t.Errorf("%f for MaxRAMPercentage should be %s", maxRamPercentage, expect)
}
}