@@ -4,14 +4,14 @@ import (
44 "testing"
55 duration "time"
66
7+ "github.com/atlassian/escalator/pkg/k8s/resource"
78 "github.com/atlassian/escalator/pkg/test"
89 "github.com/pkg/errors"
910 log "github.com/sirupsen/logrus"
1011 time "github.com/stephanos/clock"
1112 "github.com/stretchr/testify/assert"
1213 "github.com/stretchr/testify/require"
1314 v1 "k8s.io/api/core/v1"
14- "k8s.io/apimachinery/pkg/api/resource"
1515)
1616
1717type ListerOptions struct {
@@ -215,9 +215,10 @@ func TestScaleNodeGroup(t *testing.T) {
215215 }
216216
217217 tests := []struct {
218- name string
219- args args
220- err error
218+ name string
219+ args args
220+ expectedNodeDelta int
221+ err error
221222 }{
222223 {
223224 "100% cpu, 50% threshold" ,
@@ -233,6 +234,7 @@ func TestScaleNodeGroup(t *testing.T) {
233234 },
234235 ListerOptions {},
235236 },
237+ 10 ,
236238 nil ,
237239 },
238240 {
@@ -249,6 +251,7 @@ func TestScaleNodeGroup(t *testing.T) {
249251 },
250252 ListerOptions {},
251253 },
254+ 10 ,
252255 nil ,
253256 },
254257 {
@@ -265,6 +268,7 @@ func TestScaleNodeGroup(t *testing.T) {
265268 },
266269 ListerOptions {},
267270 },
271+ 5 ,
268272 nil ,
269273 },
270274 {
@@ -281,6 +285,7 @@ func TestScaleNodeGroup(t *testing.T) {
281285 },
282286 ListerOptions {},
283287 },
288+ 12 ,
284289 nil ,
285290 },
286291 {
@@ -297,6 +302,7 @@ func TestScaleNodeGroup(t *testing.T) {
297302 },
298303 ListerOptions {},
299304 },
305+ 0 ,
300306 nil ,
301307 },
302308 {
@@ -313,6 +319,7 @@ func TestScaleNodeGroup(t *testing.T) {
313319 },
314320 ListerOptions {},
315321 },
322+ 1 ,
316323 nil ,
317324 },
318325 {
@@ -327,6 +334,7 @@ func TestScaleNodeGroup(t *testing.T) {
327334 },
328335 ListerOptions {},
329336 },
337+ 0 ,
330338 errors .New ("node count less than the minimum" ),
331339 },
332340 {
@@ -341,6 +349,7 @@ func TestScaleNodeGroup(t *testing.T) {
341349 },
342350 ListerOptions {},
343351 },
352+ 0 ,
344353 errors .New ("node count larger than the maximum" ),
345354 },
346355 {
@@ -356,6 +365,7 @@ func TestScaleNodeGroup(t *testing.T) {
356365 },
357366 ListerOptions {},
358367 },
368+ 0 ,
359369 errors .New ("cannot divide by zero in percent calculation" ),
360370 },
361371 {
@@ -371,6 +381,7 @@ func TestScaleNodeGroup(t *testing.T) {
371381 },
372382 ListerOptions {},
373383 },
384+ 0 ,
374385 errors .New ("cannot divide by zero in percent calculation" ),
375386 },
376387 {
@@ -386,6 +397,7 @@ func TestScaleNodeGroup(t *testing.T) {
386397 },
387398 ListerOptions {},
388399 },
400+ 0 ,
389401 errors .New ("cannot divide by zero in percent calculation" ),
390402 },
391403 {
@@ -406,6 +418,7 @@ func TestScaleNodeGroup(t *testing.T) {
406418 },
407419 },
408420 },
421+ 0 ,
409422 errors .New ("unable to list pods" ),
410423 },
411424 {
@@ -426,6 +439,7 @@ func TestScaleNodeGroup(t *testing.T) {
426439 },
427440 },
428441 },
442+ 0 ,
429443 errors .New ("unable to list nodes" ),
430444 },
431445 {
@@ -442,6 +456,7 @@ func TestScaleNodeGroup(t *testing.T) {
442456 },
443457 ListerOptions {},
444458 },
459+ 0 ,
445460 nil ,
446461 },
447462 {
@@ -458,6 +473,7 @@ func TestScaleNodeGroup(t *testing.T) {
458473 },
459474 ListerOptions {},
460475 },
476+ 38 ,
461477 nil ,
462478 },
463479 }
@@ -507,6 +523,7 @@ func TestScaleNodeGroup(t *testing.T) {
507523 require .EqualError (t , tt .err , err .Error ())
508524 }
509525
526+ assert .Equal (t , tt .expectedNodeDelta , nodesDelta )
510527 if nodesDelta <= 0 {
511528 return
512529 }
@@ -542,7 +559,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
542559 nodeGroupOptions NodeGroupOptions
543560 listerOptions ListerOptions
544561 }
545- var defaultNodeCPUCapaity int64 = 2000
562+ var defaultNodeCPUCapacity int64 = 2000
546563 var defaultNodeMemCapacity int64 = 8000
547564
548565 tests := []struct {
@@ -557,7 +574,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
557574 {
558575 "10 nodes, 0 pods, min nodes 5, fast node removal" ,
559576 args {
560- buildTestNodes (10 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
577+ buildTestNodes (10 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
561578 buildTestPods (0 , 0 , 0 ),
562579 NodeGroupOptions {
563580 Name : "default" ,
@@ -583,7 +600,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
583600 {
584601 "10 nodes, 10 pods, slow node removal" ,
585602 args {
586- buildTestNodes (10 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
603+ buildTestNodes (10 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
587604 buildTestPods (10 , 1000 , 1000 ),
588605 NodeGroupOptions {
589606 Name : "default" ,
@@ -609,7 +626,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
609626 {
610627 "4 nodes, 0 pods, min nodes 0, fast node removal to scale down to 0" ,
611628 args {
612- buildTestNodes (4 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
629+ buildTestNodes (4 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
613630 buildTestPods (0 , 0 , 0 ),
614631 NodeGroupOptions {
615632 Name : "default" ,
@@ -635,7 +652,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
635652 {
636653 "0 nodes, 10 pods, min nodes 0, scale up from 0 without cache" ,
637654 args {
638- buildTestNodes (0 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
655+ buildTestNodes (0 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
639656 buildTestPods (40 , 200 , 800 ),
640657 NodeGroupOptions {
641658 Name : "default" ,
@@ -662,7 +679,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
662679 {
663680 "0 nodes, 10 pods, min nodes 0, scale up from 0 with cache" ,
664681 args {
665- buildTestNodes (0 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
682+ buildTestNodes (0 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
666683 buildTestPods (40 , 200 , 800 ),
667684 NodeGroupOptions {
668685 Name : "default" ,
@@ -717,8 +734,8 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
717734 // add cached node allocatable capacity when configured
718735 if tt .scaleUpWithCachedCapacity {
719736 defaultNodeGroupState := nodeGroupsState [tt .args .nodeGroupOptions .Name ]
720- defaultNodeGroupState .cpuCapacity = * resource .NewMilliQuantity ( defaultNodeCPUCapaity , resource . DecimalSI )
721- defaultNodeGroupState .memCapacity = * resource .NewQuantity (defaultNodeMemCapacity , resource . DecimalSI )
737+ defaultNodeGroupState .cpuCapacity = * resource .NewCPUQuantity ( defaultNodeCPUCapacity )
738+ defaultNodeGroupState .memCapacity = * resource .NewMemoryQuantity (defaultNodeMemCapacity )
722739 nodeGroupsState [tt .args .nodeGroupOptions .Name ] = defaultNodeGroupState
723740 }
724741
0 commit comments