@@ -4,14 +4,14 @@ import (
4
4
"testing"
5
5
duration "time"
6
6
7
+ "github.com/atlassian/escalator/pkg/k8s/resource"
7
8
"github.com/atlassian/escalator/pkg/test"
8
9
"github.com/pkg/errors"
9
10
log "github.com/sirupsen/logrus"
10
11
time "github.com/stephanos/clock"
11
12
"github.com/stretchr/testify/assert"
12
13
"github.com/stretchr/testify/require"
13
14
v1 "k8s.io/api/core/v1"
14
- "k8s.io/apimachinery/pkg/api/resource"
15
15
)
16
16
17
17
type ListerOptions struct {
@@ -215,9 +215,10 @@ func TestScaleNodeGroup(t *testing.T) {
215
215
}
216
216
217
217
tests := []struct {
218
- name string
219
- args args
220
- err error
218
+ name string
219
+ args args
220
+ expectedNodeDelta int
221
+ err error
221
222
}{
222
223
{
223
224
"100% cpu, 50% threshold" ,
@@ -233,6 +234,7 @@ func TestScaleNodeGroup(t *testing.T) {
233
234
},
234
235
ListerOptions {},
235
236
},
237
+ 10 ,
236
238
nil ,
237
239
},
238
240
{
@@ -249,6 +251,7 @@ func TestScaleNodeGroup(t *testing.T) {
249
251
},
250
252
ListerOptions {},
251
253
},
254
+ 10 ,
252
255
nil ,
253
256
},
254
257
{
@@ -265,6 +268,7 @@ func TestScaleNodeGroup(t *testing.T) {
265
268
},
266
269
ListerOptions {},
267
270
},
271
+ 5 ,
268
272
nil ,
269
273
},
270
274
{
@@ -281,6 +285,7 @@ func TestScaleNodeGroup(t *testing.T) {
281
285
},
282
286
ListerOptions {},
283
287
},
288
+ 12 ,
284
289
nil ,
285
290
},
286
291
{
@@ -297,6 +302,7 @@ func TestScaleNodeGroup(t *testing.T) {
297
302
},
298
303
ListerOptions {},
299
304
},
305
+ 0 ,
300
306
nil ,
301
307
},
302
308
{
@@ -313,6 +319,7 @@ func TestScaleNodeGroup(t *testing.T) {
313
319
},
314
320
ListerOptions {},
315
321
},
322
+ 1 ,
316
323
nil ,
317
324
},
318
325
{
@@ -327,6 +334,7 @@ func TestScaleNodeGroup(t *testing.T) {
327
334
},
328
335
ListerOptions {},
329
336
},
337
+ 0 ,
330
338
errors .New ("node count less than the minimum" ),
331
339
},
332
340
{
@@ -341,6 +349,7 @@ func TestScaleNodeGroup(t *testing.T) {
341
349
},
342
350
ListerOptions {},
343
351
},
352
+ 0 ,
344
353
errors .New ("node count larger than the maximum" ),
345
354
},
346
355
{
@@ -356,6 +365,7 @@ func TestScaleNodeGroup(t *testing.T) {
356
365
},
357
366
ListerOptions {},
358
367
},
368
+ 0 ,
359
369
errors .New ("cannot divide by zero in percent calculation" ),
360
370
},
361
371
{
@@ -371,6 +381,7 @@ func TestScaleNodeGroup(t *testing.T) {
371
381
},
372
382
ListerOptions {},
373
383
},
384
+ 0 ,
374
385
errors .New ("cannot divide by zero in percent calculation" ),
375
386
},
376
387
{
@@ -386,6 +397,7 @@ func TestScaleNodeGroup(t *testing.T) {
386
397
},
387
398
ListerOptions {},
388
399
},
400
+ 0 ,
389
401
errors .New ("cannot divide by zero in percent calculation" ),
390
402
},
391
403
{
@@ -406,6 +418,7 @@ func TestScaleNodeGroup(t *testing.T) {
406
418
},
407
419
},
408
420
},
421
+ 0 ,
409
422
errors .New ("unable to list pods" ),
410
423
},
411
424
{
@@ -426,6 +439,7 @@ func TestScaleNodeGroup(t *testing.T) {
426
439
},
427
440
},
428
441
},
442
+ 0 ,
429
443
errors .New ("unable to list nodes" ),
430
444
},
431
445
{
@@ -442,6 +456,7 @@ func TestScaleNodeGroup(t *testing.T) {
442
456
},
443
457
ListerOptions {},
444
458
},
459
+ 0 ,
445
460
nil ,
446
461
},
447
462
{
@@ -458,6 +473,7 @@ func TestScaleNodeGroup(t *testing.T) {
458
473
},
459
474
ListerOptions {},
460
475
},
476
+ 38 ,
461
477
nil ,
462
478
},
463
479
}
@@ -507,6 +523,7 @@ func TestScaleNodeGroup(t *testing.T) {
507
523
require .EqualError (t , tt .err , err .Error ())
508
524
}
509
525
526
+ assert .Equal (t , tt .expectedNodeDelta , nodesDelta )
510
527
if nodesDelta <= 0 {
511
528
return
512
529
}
@@ -542,7 +559,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
542
559
nodeGroupOptions NodeGroupOptions
543
560
listerOptions ListerOptions
544
561
}
545
- var defaultNodeCPUCapaity int64 = 2000
562
+ var defaultNodeCPUCapacity int64 = 2000
546
563
var defaultNodeMemCapacity int64 = 8000
547
564
548
565
tests := []struct {
@@ -557,7 +574,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
557
574
{
558
575
"10 nodes, 0 pods, min nodes 5, fast node removal" ,
559
576
args {
560
- buildTestNodes (10 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
577
+ buildTestNodes (10 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
561
578
buildTestPods (0 , 0 , 0 ),
562
579
NodeGroupOptions {
563
580
Name : "default" ,
@@ -583,7 +600,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
583
600
{
584
601
"10 nodes, 10 pods, slow node removal" ,
585
602
args {
586
- buildTestNodes (10 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
603
+ buildTestNodes (10 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
587
604
buildTestPods (10 , 1000 , 1000 ),
588
605
NodeGroupOptions {
589
606
Name : "default" ,
@@ -609,7 +626,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
609
626
{
610
627
"4 nodes, 0 pods, min nodes 0, fast node removal to scale down to 0" ,
611
628
args {
612
- buildTestNodes (4 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
629
+ buildTestNodes (4 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
613
630
buildTestPods (0 , 0 , 0 ),
614
631
NodeGroupOptions {
615
632
Name : "default" ,
@@ -635,7 +652,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
635
652
{
636
653
"0 nodes, 10 pods, min nodes 0, scale up from 0 without cache" ,
637
654
args {
638
- buildTestNodes (0 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
655
+ buildTestNodes (0 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
639
656
buildTestPods (40 , 200 , 800 ),
640
657
NodeGroupOptions {
641
658
Name : "default" ,
@@ -662,7 +679,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
662
679
{
663
680
"0 nodes, 10 pods, min nodes 0, scale up from 0 with cache" ,
664
681
args {
665
- buildTestNodes (0 , defaultNodeCPUCapaity , defaultNodeMemCapacity ),
682
+ buildTestNodes (0 , defaultNodeCPUCapacity , defaultNodeMemCapacity ),
666
683
buildTestPods (40 , 200 , 800 ),
667
684
NodeGroupOptions {
668
685
Name : "default" ,
@@ -717,8 +734,8 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
717
734
// add cached node allocatable capacity when configured
718
735
if tt .scaleUpWithCachedCapacity {
719
736
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 )
722
739
nodeGroupsState [tt .args .nodeGroupOptions .Name ] = defaultNodeGroupState
723
740
}
724
741
0 commit comments