Skip to content

Commit

Permalink
[YUNIKORN-2842] Improve metadata & gang_utils funtion's test coverage (
Browse files Browse the repository at this point in the history
…#903)

Closes: #903

Signed-off-by: Peter Bacsko <[email protected]>
  • Loading branch information
SP12893678 authored and pbacsko committed Aug 28, 2024
1 parent 874759b commit f8e9c11
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cache/gang_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func Test_GetPlaceholderResourceRequest(t *testing.T) {
{"base", map[string]resource.Quantity{"pods": resource.MustParse("1")}, v1.ResourceList{"pods": resource.MustParse("1")}},
{"hugepages", map[string]resource.Quantity{"hugepages-huge": resource.MustParse("2")}, v1.ResourceList{"hugepages-huge": resource.MustParse("2")}},
{"mixed", map[string]resource.Quantity{"pods": resource.MustParse("4"), "nvidia.com/gpu": resource.MustParse("5")}, v1.ResourceList{"pods": resource.MustParse("4"), "nvidia.com/gpu": resource.MustParse("5")}},
{"empty key", map[string]resource.Quantity{"": resource.MustParse("1")}, v1.ResourceList{}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
34 changes: 34 additions & 0 deletions pkg/cache/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,16 @@ func TestGetTaskMetadata(t *testing.T) {
assert.Equal(t, task.ApplicationID, "yunikorn-default-autogen")
assert.Equal(t, task.TaskID, "UID-POD-00001")
assert.Equal(t, task.TaskGroupName, "")

// case: empty pod
task, ok = getTaskMetadata(&v1.Pod{})
assert.Equal(t, ok, false)
assert.DeepEqual(t, task, TaskMetadata{})
}

func TestGetAppMetadata(t *testing.T) { //nolint:funlen
conf.GetSchedulerConf().SetTestMode(true)

defer utils.SetPluginMode(false)
defer func() { conf.GetSchedulerConf().GenerateUniqueAppIds = false }()
utils.SetPluginMode(false)
Expand Down Expand Up @@ -301,6 +308,33 @@ func TestGetAppMetadata(t *testing.T) { //nolint:funlen
utils.SetPluginMode(true)
app, ok = getAppMetadata(&pod)
assert.Equal(t, ok, false)

// case: invalid annotation task groups
pod = v1.Pod{
TypeMeta: apis.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: apis.ObjectMeta{
Name: "pod00001",
Namespace: "default",
UID: "UID-POD-00001",
Labels: map[string]string{
"applicationId": "app00001",
"queue": "root.a",
},
Annotations: map[string]string{
constants.AnnotationTaskGroups: "{ name:\"\" }",
},
},
Spec: v1.PodSpec{SchedulerName: constants.SchedulerName},
Status: v1.PodStatus{Phase: v1.PodPending},
}
app, ok = getAppMetadata(&pod)
assert.Equal(t, ok, true)
assert.Equal(t, app.SchedulingPolicyParameters.GetGangSchedulingStyle(), "Soft")
assert.Equal(t, app.Tags[common.AppTagCreateForce], "false")
assert.Equal(t, len(app.TaskGroups), 0)
}

func TestGetOwnerReferences(t *testing.T) {
Expand Down

0 comments on commit f8e9c11

Please sign in to comment.