-
Notifications
You must be signed in to change notification settings - Fork 15
/
watermarks_test.go
54 lines (42 loc) · 1.57 KB
/
watermarks_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
package watchdog
import (
"testing"
"github.com/benbjohnson/clock"
"github.com/stretchr/testify/require"
)
var (
watermarks = []float64{0.50, 0.75, 0.80}
thresholds = func() []uint64 {
var ret []uint64
for _, w := range watermarks {
ret = append(ret, uint64(float64(limit64MiB)*w))
}
return ret
}()
)
func TestProgressiveWatermarks(t *testing.T) {
clk := clock.NewMock()
Clock = clk
p, err := NewWatermarkPolicy(watermarks...)(limit64MiB)
require.NoError(t, err)
// at zero
next := p.Evaluate(UtilizationSystem, uint64(0))
require.EqualValues(t, thresholds[0], next)
// before the watermark.
next = p.Evaluate(UtilizationSystem, uint64(float64(limit64MiB)*watermarks[0])-1)
require.EqualValues(t, thresholds[0], next)
// exactly at the watermark; gives us the next watermark, as the watchdodg would've
// taken care of triggering the first watermark.
next = p.Evaluate(UtilizationSystem, uint64(float64(limit64MiB)*watermarks[0]))
require.EqualValues(t, thresholds[1], next)
// after the watermark gives us the next watermark.
next = p.Evaluate(UtilizationSystem, uint64(float64(limit64MiB)*watermarks[0])+1)
require.EqualValues(t, thresholds[1], next)
// last watermark; disable the policy.
next = p.Evaluate(UtilizationSystem, uint64(float64(limit64MiB)*watermarks[2]))
require.EqualValues(t, PolicyTempDisabled, next)
next = p.Evaluate(UtilizationSystem, uint64(float64(limit64MiB)*watermarks[2]+1))
require.EqualValues(t, PolicyTempDisabled, next)
next = p.Evaluate(UtilizationSystem, limit64MiB)
require.EqualValues(t, PolicyTempDisabled, next)
}