@@ -716,6 +716,82 @@ func TestScoreFitBinPack(t *testing.T) {
716
716
}
717
717
}
718
718
719
+ func TestAllocsFit_MaxNodeAllocs (t * testing.T ) {
720
+ ci .Parallel (t )
721
+ baseAlloc := & Allocation {
722
+ AllocatedResources : & AllocatedResources {
723
+ Tasks : map [string ]* AllocatedTaskResources {
724
+ "web" : {
725
+ Cpu : AllocatedCpuResources {
726
+ CpuShares : 1000 ,
727
+ ReservedCores : []uint16 {},
728
+ },
729
+ Memory : AllocatedMemoryResources {
730
+ MemoryMB : 1024 ,
731
+ },
732
+ },
733
+ },
734
+ Shared : AllocatedSharedResources {
735
+ DiskMB : 5000 ,
736
+ Networks : Networks {
737
+ {
738
+ Mode : "host" ,
739
+ IP : "10.0.0.1" ,
740
+ ReservedPorts : []Port {{Label : "main" , Value : 8000 }},
741
+ },
742
+ },
743
+ Ports : AllocatedPorts {
744
+ {
745
+ Label : "main" ,
746
+ Value : 8000 ,
747
+ HostIP : "10.0.0.1" ,
748
+ },
749
+ },
750
+ },
751
+ },
752
+ }
753
+
754
+ testCases := []struct {
755
+ name string
756
+ allocations []* Allocation
757
+ expectErr bool
758
+ maxAllocs int
759
+ }{
760
+ {
761
+ name : "happy_path" ,
762
+ allocations : []* Allocation {baseAlloc },
763
+ expectErr : false ,
764
+ maxAllocs : 2 ,
765
+ },
766
+ {
767
+ name : "too many allocs" ,
768
+ allocations : []* Allocation {baseAlloc , baseAlloc , baseAlloc },
769
+ expectErr : true ,
770
+ maxAllocs : 2 ,
771
+ },
772
+ }
773
+
774
+ for _ , tc := range testCases {
775
+ t .Run (tc .name , func (t * testing.T ) {
776
+ n := node2k ()
777
+ n .NodeAllocationTracker = & NodeAllocationTracker {false , tc .maxAllocs }
778
+ fit , dim , used , err := AllocsFit (n , tc .allocations , nil , false )
779
+ if ! tc .expectErr {
780
+ must .NoError (t , err )
781
+ must .True (t , fit )
782
+ must .Eq (t , 1000 , used .Flattened .Cpu .CpuShares )
783
+ must .Eq (t , 1024 , used .Flattened .Memory .MemoryMB )
784
+ } else {
785
+ must .Error (t , err )
786
+ must .False (t , fit )
787
+ must .StrContains (t , dim , "max allocation exceeded" )
788
+ must .StrContains (t , err .Error (), "plan exceeds max allocation" )
789
+ must .Eq (t , 0 , used .Flattened .Cpu .CpuShares )
790
+ must .Eq (t , 0 , used .Flattened .Memory .MemoryMB )
791
+ }
792
+ })
793
+ }
794
+ }
719
795
func TestACLPolicyListHash (t * testing.T ) {
720
796
ci .Parallel (t )
721
797
0 commit comments