Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
GonzaloSaez committed Oct 31, 2024
1 parent 1a2e91b commit c0a34b9
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions pkg/controller/podgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ var (
corev1.ResourceMemory: resource.MustParse("512Gi"),
"example.com/gpu": resource.MustParse("40"),
}

minResourcesNoMinMember = &corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
}
)

func TestNewPodGroup(t *testing.T) {
Expand Down Expand Up @@ -208,6 +213,73 @@ func TestNewPodGroup(t *testing.T) {
},
},
},
"no worker no MinResources": {
mpiJob: &kubeflow.MPIJob{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Annotations: map[string]string{
volcanov1beta1.QueueNameAnnotationKey: "project-x",
},
},
Spec: kubeflow.MPIJobSpec{
RunLauncherAsWorker: ptr.To[bool](true),
RunPolicy: kubeflow.RunPolicy{
SchedulingPolicy: &kubeflow.SchedulingPolicy{
MinAvailable: ptr.To[int32](1),
Queue: "project-y",
PriorityClass: "high",
ScheduleTimeoutSeconds: ptr.To[int32](100),
},
},
MPIReplicaSpecs: map[kubeflow.MPIReplicaType]*kubeflow.ReplicaSpec{
kubeflow.MPIReplicaTypeLauncher: {
Replicas: ptr.To[int32](1),
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
},
},
}},
},
},
},
},
},
},
wantVolcanoPG: &volcanov1beta1.PodGroup{
TypeMeta: metav1.TypeMeta{
APIVersion: volcanov1beta1.SchemeGroupVersion.String(),
Kind: "PodGroup",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: volcanov1beta1.PodGroupSpec{
MinMember: 1,
Queue: "project-y",
PriorityClassName: "high",
MinResources: minResourcesNoMinMember,
},
},
wantSchedPG: &schedv1alpha1.PodGroup{
TypeMeta: metav1.TypeMeta{
APIVersion: schedv1alpha1.SchemeGroupVersion.String(),
Kind: "PodGroup",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: schedv1alpha1.PodGroupSpec{
MinMember: 1,
MinResources: *minResourcesNoMinMember,
ScheduleTimeoutSeconds: ptr.To[int32](100),
},
},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
Expand Down

0 comments on commit c0a34b9

Please sign in to comment.