-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(elastic): Implement main feature
Signed-off-by: Ce Gao <ce.gao@outlook.com>
- Loading branch information
Showing
13 changed files
with
690 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package v1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/onsi/ginkgo" | ||
"github.com/onsi/gomega" | ||
|
||
v1 "github.com/kubeflow/common/pkg/apis/common/v1" | ||
) | ||
|
||
func TestSetElasticPolicy(t *testing.T) { | ||
gomega.RegisterFailHandler(ginkgo.Fail) | ||
|
||
type args struct { | ||
job *PyTorchJob | ||
} | ||
type result struct { | ||
expectedMinReplicas *int32 | ||
expectedMaxReplicas *int32 | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
result result | ||
}{ | ||
{ | ||
name: "minReplicas and maxReplicas to null", | ||
args: args{ | ||
job: &PyTorchJob{ | ||
Spec: PyTorchJobSpec{ | ||
ElasticPolicy: &ElasticPolicy{}, | ||
PyTorchReplicaSpecs: map[v1.ReplicaType]*v1.ReplicaSpec{ | ||
PyTorchReplicaTypeWorker: { | ||
Replicas: int32Ptr(1), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
result: result{ | ||
expectedMinReplicas: int32Ptr(1), | ||
expectedMaxReplicas: int32Ptr(1), | ||
}, | ||
}, | ||
{ | ||
name: "minReplicas and maxReplicas to 1", | ||
args: args{ | ||
job: &PyTorchJob{ | ||
Spec: PyTorchJobSpec{ | ||
ElasticPolicy: &ElasticPolicy{ | ||
MaxReplicas: int32Ptr(1), | ||
MinReplicas: int32Ptr(1), | ||
}, | ||
PyTorchReplicaSpecs: map[v1.ReplicaType]*v1.ReplicaSpec{ | ||
PyTorchReplicaTypeWorker: { | ||
Replicas: int32Ptr(1), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
result: result{ | ||
expectedMinReplicas: int32Ptr(1), | ||
expectedMaxReplicas: int32Ptr(1), | ||
}, | ||
}, | ||
{ | ||
name: "minReplicas and maxReplicas to 1", | ||
args: args{ | ||
job: &PyTorchJob{ | ||
Spec: PyTorchJobSpec{ | ||
ElasticPolicy: &ElasticPolicy{ | ||
MaxReplicas: int32Ptr(1), | ||
MinReplicas: int32Ptr(1), | ||
}, | ||
PyTorchReplicaSpecs: map[v1.ReplicaType]*v1.ReplicaSpec{ | ||
PyTorchReplicaTypeWorker: { | ||
Replicas: int32Ptr(1), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
result: result{ | ||
expectedMinReplicas: int32Ptr(1), | ||
expectedMaxReplicas: int32Ptr(1), | ||
}, | ||
}, | ||
{ | ||
name: "minReplicas to null, maxRepliacs to 1", | ||
args: args{ | ||
job: &PyTorchJob{ | ||
Spec: PyTorchJobSpec{ | ||
ElasticPolicy: &ElasticPolicy{ | ||
MaxReplicas: int32Ptr(1), | ||
MinReplicas: nil, | ||
}, | ||
PyTorchReplicaSpecs: map[v1.ReplicaType]*v1.ReplicaSpec{ | ||
PyTorchReplicaTypeWorker: { | ||
Replicas: int32Ptr(1), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
result: result{ | ||
expectedMinReplicas: int32Ptr(1), | ||
expectedMaxReplicas: int32Ptr(1), | ||
}, | ||
}, | ||
{ | ||
name: "maxRepliacs to null, minReplicas to 1", | ||
args: args{ | ||
job: &PyTorchJob{ | ||
Spec: PyTorchJobSpec{ | ||
ElasticPolicy: &ElasticPolicy{ | ||
MaxReplicas: nil, | ||
MinReplicas: int32Ptr(1), | ||
}, | ||
PyTorchReplicaSpecs: map[v1.ReplicaType]*v1.ReplicaSpec{ | ||
PyTorchReplicaTypeWorker: { | ||
Replicas: int32Ptr(1), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
result: result{ | ||
expectedMinReplicas: int32Ptr(1), | ||
expectedMaxReplicas: int32Ptr(1), | ||
}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
setElasticPolicy(test.args.job) | ||
if test.result.expectedMinReplicas != nil { | ||
gomega.Expect(test.args.job.Spec.ElasticPolicy.MinReplicas). | ||
To(gomega.Equal(test.result.expectedMinReplicas)) | ||
} else { | ||
gomega.Expect(test.args.job.Spec.ElasticPolicy.MinReplicas). | ||
To(gomega.BeNil()) | ||
} | ||
|
||
if test.result.expectedMaxReplicas != nil { | ||
gomega.Expect(test.args.job.Spec.ElasticPolicy.MaxReplicas). | ||
To(gomega.Equal(test.result.expectedMaxReplicas)) | ||
} else { | ||
gomega.Expect(test.args.job.Spec.ElasticPolicy.MaxReplicas). | ||
To(gomega.BeNil()) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func int32Ptr(n int) *int32 { | ||
val := int32(n) | ||
return &val | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.