@@ -545,135 +545,96 @@ func TestGetWorkerGroupDesiredReplicas(t *testing.T) {
545545 assert .Equal (t , GetWorkerGroupDesiredReplicas (ctx , workerGroupSpec ), replicas * numOfHosts )
546546}
547547
548- func TestCalculateMinReplicas (t * testing.T ) {
548+ func TestCalculateMinAndMaxReplicas (t * testing.T ) {
549549 suspend := true
550550
551551 tests := []struct {
552552 name string
553553 specs []rayv1.WorkerGroupSpec
554- expected int32
554+ expected struct {
555+ minReplicas int32
556+ maxReplicas int32
557+ }
555558 }{
556559 {
557560 name : "Single group with one host" ,
558561 specs : []rayv1.WorkerGroupSpec {
559562 {
560563 NumOfHosts : 1 ,
561564 MinReplicas : ptr.To [int32 ](2 ),
565+ MaxReplicas : ptr.To [int32 ](3 ),
562566 },
563567 },
564- expected : 2 ,
568+ expected : struct {
569+ minReplicas int32
570+ maxReplicas int32
571+ }{
572+ minReplicas : 2 ,
573+ maxReplicas : 3 ,
574+ },
565575 },
566576 {
567577 name : "Single group with four hosts" ,
568578 specs : []rayv1.WorkerGroupSpec {
569579 {
570580 NumOfHosts : 4 ,
571581 MinReplicas : ptr.To [int32 ](2 ),
572- },
573- },
574- expected : 8 ,
575- },
576- {
577- name : "Two worker groups: one with a single host, one with two hosts" ,
578- specs : []rayv1.WorkerGroupSpec {
579- {
580- NumOfHosts : 1 ,
581- MinReplicas : ptr.To [int32 ](4 ),
582- },
583- {
584- NumOfHosts : 2 ,
585- MinReplicas : ptr.To [int32 ](3 ),
586- },
587- },
588- expected : 10 ,
589- },
590- {
591- name : "Two groups with suspended" ,
592- specs : []rayv1.WorkerGroupSpec {
593- {
594- NumOfHosts : 1 ,
595- MinReplicas : ptr.To [int32 ](3 ),
596- Suspend : & suspend ,
597- },
598- {
599- NumOfHosts : 1 ,
600- MinReplicas : ptr.To [int32 ](1 ),
601- Suspend : & suspend ,
602- },
603- },
604- expected : 0 ,
605- },
606- }
607-
608- for _ , tt := range tests {
609- t .Run (tt .name , func (t * testing.T ) {
610- cluster := & rayv1.RayCluster {
611- Spec : rayv1.RayClusterSpec {
612- WorkerGroupSpecs : tt .specs ,
613- },
614- }
615- assert .Equal (t , tt .expected , CalculateMinReplicas (cluster ))
616- })
617- }
618- }
619-
620- func TestCalculateMaxReplicas (t * testing.T ) {
621- suspend := true
622-
623- tests := []struct {
624- name string
625- specs []rayv1.WorkerGroupSpec
626- expected int32
627- }{
628- {
629- name : "Single group with one host" ,
630- specs : []rayv1.WorkerGroupSpec {
631- {
632- NumOfHosts : 1 ,
633582 MaxReplicas : ptr.To [int32 ](3 ),
634583 },
635584 },
636- expected : 3 ,
637- },
638- {
639- name : "Single group with four hosts" ,
640- specs : []rayv1.WorkerGroupSpec {
641- {
642- NumOfHosts : 4 ,
643- MaxReplicas : ptr.To [int32 ](3 ),
644- },
585+ expected : struct {
586+ minReplicas int32
587+ maxReplicas int32
588+ }{
589+ minReplicas : 8 ,
590+ maxReplicas : 12 ,
645591 },
646- expected : 12 ,
647592 },
648593 {
649594 name : "Two worker groups: one with a single host, one with two hosts" ,
650595 specs : []rayv1.WorkerGroupSpec {
651596 {
652597 NumOfHosts : 1 ,
598+ MinReplicas : ptr.To [int32 ](4 ),
653599 MaxReplicas : ptr.To [int32 ](4 ),
654600 },
655601 {
656602 NumOfHosts : 2 ,
603+ MinReplicas : ptr.To [int32 ](3 ),
657604 MaxReplicas : ptr.To [int32 ](3 ),
658605 },
659606 },
660- expected : 10 ,
607+ expected : struct {
608+ minReplicas int32
609+ maxReplicas int32
610+ }{
611+ minReplicas : 10 ,
612+ maxReplicas : 10 ,
613+ },
661614 },
662615 {
663616 name : "Two groups with suspended" ,
664617 specs : []rayv1.WorkerGroupSpec {
665618 {
666619 NumOfHosts : 1 ,
620+ MinReplicas : ptr.To [int32 ](3 ),
667621 MaxReplicas : ptr.To [int32 ](3 ),
668622 Suspend : & suspend ,
669623 },
670624 {
671625 NumOfHosts : 1 ,
626+ MinReplicas : ptr.To [int32 ](1 ),
672627 MaxReplicas : ptr.To [int32 ](1 ),
673628 Suspend : & suspend ,
674629 },
675630 },
676- expected : 0 ,
631+ expected : struct {
632+ minReplicas int32
633+ maxReplicas int32
634+ }{
635+ minReplicas : 0 ,
636+ maxReplicas : 0 ,
637+ },
677638 },
678639 }
679640
@@ -684,7 +645,11 @@ func TestCalculateMaxReplicas(t *testing.T) {
684645 WorkerGroupSpecs : tt .specs ,
685646 },
686647 }
687- assert .Equal (t , tt .expected , CalculateMaxReplicas (cluster ))
648+
649+ // Check min replicas
650+ assert .Equal (t , tt .expected .minReplicas , CalculateMinReplicas (cluster ))
651+ // Check max replicas
652+ assert .Equal (t , tt .expected .maxReplicas , CalculateMaxReplicas (cluster ))
688653 })
689654 }
690655}
0 commit comments