volcano.sh/volcano@v1.9.0/pkg/scheduler/plugins/predicates/proportional_test.go (about) 1 package predicates 2 3 import ( 4 "testing" 5 6 v1 "k8s.io/api/core/v1" 7 8 "volcano.sh/volcano/pkg/scheduler/api" 9 ) 10 11 func buildTask(name, cpu, memory, gpu string) *api.TaskInfo { 12 return &api.TaskInfo{ 13 Name: name, 14 Resreq: api.NewResource(api.BuildResourceListWithGPU(cpu, memory, gpu)), 15 } 16 } 17 18 func buildNode(name, cpu, memory, gpu string) *api.NodeInfo { 19 return &api.NodeInfo{ 20 Name: name, 21 Idle: api.NewResource(api.BuildResourceListWithGPU(cpu, memory, gpu)), 22 } 23 } 24 25 func Test_checkNodeResourceIsProportional(t *testing.T) { 26 27 t1 := buildTask("t1", "4", "4G", "0") 28 t2 := buildTask("t1", "10", "10G", "0") 29 t3 := buildTask("t1", "10", "10G", "1") 30 n1 := buildNode("n1", "30", "30G", "6") 31 n2 := buildNode("n2", "26", "26G", "2") 32 proportional := map[v1.ResourceName]baseResource{ 33 "nvidia.com/gpu": { 34 CPU: 4, 35 Memory: 4, 36 }, 37 } 38 39 type args struct { 40 task *api.TaskInfo 41 node *api.NodeInfo 42 proportional map[v1.ResourceName]baseResource 43 } 44 tests := []struct { 45 name string 46 args args 47 want int 48 wantErr bool 49 }{ 50 { 51 "cpu_task_less_than_reserved_resource", 52 args{ 53 task: t1, 54 node: n1, 55 proportional: proportional, 56 }, 57 api.Success, 58 false, 59 }, 60 { 61 "cpu_task_greater_than_reserved_resource", 62 args{ 63 task: t2, 64 node: n1, 65 proportional: proportional, 66 }, 67 api.UnschedulableAndUnresolvable, 68 true, 69 }, 70 { 71 "gpu_task_no_proportional_check", 72 args{ 73 task: t3, 74 node: n1, 75 proportional: proportional, 76 }, 77 api.Success, 78 false, 79 }, 80 { 81 "cpu_task_less_than_idle_resource", 82 args{ 83 task: t2, 84 node: n2, 85 proportional: proportional, 86 }, 87 api.Success, 88 false, 89 }, 90 } 91 for _, tt := range tests { 92 t.Run(tt.name, func(t *testing.T) { 93 got, err := checkNodeResourceIsProportional(tt.args.task, tt.args.node, tt.args.proportional) 94 if (err != nil) != tt.wantErr { 95 t.Errorf("checkNodeResourceIsProportional() error = %v, wantErr %v", err, tt.wantErr) 96 return 97 } 98 if got.Code != tt.want { 99 t.Errorf("checkNodeResourceIsProportional() got = %v, want %v", got, tt.want) 100 } 101 }) 102 } 103 }