@@ -109,6 +109,53 @@ func TestMemoryScore(t *testing.T) {
109109 }
110110}
111111
112+ func TestMemoryUsage (t * testing.T ) {
113+ tests := []struct {
114+ memory []float64
115+ ts []model.Time
116+ lastUsage float64
117+ timeToOOM time.Duration
118+ }{
119+ {
120+ memory : []float64 {0.2 , 0.3 },
121+ ts : []model.Time {model .Time (15000 ), model .Time (30000 )},
122+ lastUsage : 0.3 ,
123+ timeToOOM : 90 * time .Second ,
124+ },
125+ {
126+ memory : []float64 {0.2 , 0.3 , 0.3 },
127+ ts : []model.Time {model .Time (15000 ), model .Time (30000 ), model .Time (31000 )},
128+ lastUsage : 0.3 ,
129+ timeToOOM : 96 * time .Second ,
130+ },
131+ {
132+ memory : []float64 {0.3 , 0.3 },
133+ ts : []model.Time {model .Time (30000 ), model .Time (31000 )},
134+ lastUsage : 0.3 ,
135+ timeToOOM : time .Duration (math .MaxInt ),
136+ },
137+ {
138+ memory : []float64 {0.3 , 0.3 },
139+ ts : []model.Time {model .Time (30000 ), model .Time (45000 )},
140+ lastUsage : 0.3 ,
141+ timeToOOM : time .Duration (math .MaxInt ),
142+ },
143+ {
144+ memory : []float64 {0.3 , 0.2 },
145+ ts : []model.Time {model .Time (30000 ), model .Time (45000 )},
146+ lastUsage : 0.2 ,
147+ timeToOOM : time .Duration (math .MaxInt ),
148+ },
149+ }
150+
151+ for i , test := range tests {
152+ pairs := createPairs (test .memory , test .ts )
153+ latestUsage , timeToOOM := calcMemUsage (pairs )
154+ require .Equal (t , test .lastUsage , latestUsage , "test index %d" , i )
155+ require .Equal (t , test .timeToOOM , timeToOOM , "test index %d" , i )
156+ }
157+ }
158+
112159func TestMemoryBalance (t * testing.T ) {
113160 tests := []struct {
114161 memory [][]float64
0 commit comments