2020-12-04 13:08:00 +00:00
|
|
|
package watchdog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/raulk/clock"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAdaptivePolicy(t *testing.T) {
|
|
|
|
clk := clock.NewMock()
|
|
|
|
Clock = clk
|
|
|
|
|
2021-01-19 19:38:46 +00:00
|
|
|
p, err := NewAdaptivePolicy(0.5)(limit64MiB)
|
2020-12-04 13:08:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// at zero; next = 50%.
|
2020-12-09 15:35:23 +00:00
|
|
|
next := p.Evaluate(UtilizationSystem, 0)
|
2021-01-19 19:38:46 +00:00
|
|
|
require.EqualValues(t, limit64MiB/2, next)
|
2020-12-04 13:08:00 +00:00
|
|
|
|
|
|
|
// at half; next = 75%.
|
2021-01-19 19:38:46 +00:00
|
|
|
next = p.Evaluate(UtilizationSystem, limit64MiB/2)
|
|
|
|
require.EqualValues(t, 3*(limit64MiB/4), next)
|
2020-12-04 13:08:00 +00:00
|
|
|
|
2021-01-20 10:41:55 +00:00
|
|
|
// at limit.
|
2021-01-19 19:38:46 +00:00
|
|
|
next = p.Evaluate(UtilizationSystem, limit64MiB)
|
|
|
|
require.EqualValues(t, limit64MiB, next)
|
2020-12-04 13:08:00 +00:00
|
|
|
}
|