volcano.sh/volcano@v1.9.0/pkg/webhooks/admission/jobs/plugins/mpi/mpi_test.go (about)

     1  /*
     2  Copyright 2022 The Volcano Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package mpi
    18  
    19  import (
    20  	"testing"
    21  
    22  	v1 "k8s.io/api/core/v1"
    23  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    24  
    25  	"volcano.sh/apis/pkg/apis/batch/v1alpha1"
    26  	controllerMpi "volcano.sh/volcano/pkg/controllers/job/plugins/distributed-framework/mpi"
    27  )
    28  
    29  func TestMpi(t *testing.T) {
    30  	workerName := "fakeWorker"
    31  	masterName := "fakeMaster"
    32  	plugins := make(map[string][]string)
    33  	plugins[controllerMpi.MPIPluginName] = []string{"--master=" + masterName, "--worker=" + workerName}
    34  	testcases := []struct {
    35  		Name string
    36  		Job  *v1alpha1.Job
    37  	}{
    38  		{
    39  			Name: "add dependsOn",
    40  			Job: &v1alpha1.Job{
    41  				ObjectMeta: metav1.ObjectMeta{Name: "test-mpi-0"},
    42  				Spec: v1alpha1.JobSpec{
    43  					Plugins: plugins,
    44  					Tasks: []v1alpha1.TaskSpec{
    45  						{
    46  							Name:     masterName,
    47  							Replicas: 1,
    48  							Template: v1.PodTemplateSpec{},
    49  						},
    50  						{
    51  							Name:     workerName,
    52  							Replicas: 2,
    53  							Template: v1.PodTemplateSpec{},
    54  						},
    55  					},
    56  				},
    57  			},
    58  		},
    59  	}
    60  
    61  	for index, testcase := range testcases {
    62  		t.Run(testcase.Name, func(t *testing.T) {
    63  			AddDependsOn(testcase.Job)
    64  			if testcase.Job.Spec.Tasks[0].DependsOn == nil || len(testcase.Job.Spec.Tasks[0].DependsOn.Name) == 0 {
    65  				t.Errorf("Case %d (%s): no dependencies added ", index, testcase.Name)
    66  				return
    67  			}
    68  			if testcase.Job.Spec.Tasks[0].DependsOn.Name[0] != workerName {
    69  				t.Errorf("Case %d (%s): Dependency add error expect %s, but got %s", index, testcase.Name, workerName, testcase.Job.Spec.Tasks[0].DependsOn.Name[0])
    70  			}
    71  		})
    72  	}
    73  }