This is an automated email from the ASF dual-hosted git repository.

ccondit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git


The following commit(s) were added to refs/heads/master by this push:
     new c8493d95 [YUNIKORN-2851] Improve placeholder / manager test coverage 
(#905)
c8493d95 is described below

commit c8493d95f81203ec627290258cd1f64eb897d98d
Author: SP12893678 <[email protected]>
AuthorDate: Wed Sep 4 10:34:24 2024 -0500

    [YUNIKORN-2851] Improve placeholder / manager test coverage (#905)
    
    Closes: #905
    
    Signed-off-by: Craig Condit <[email protected]>
---
 pkg/cache/placeholder_manager_test.go | 42 +++++++++++++++++++++++++++++++----
 pkg/cache/placeholder_test.go         |  4 +++-
 2 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/pkg/cache/placeholder_manager_test.go 
b/pkg/cache/placeholder_manager_test.go
index 799d559d..316f235e 100644
--- a/pkg/cache/placeholder_manager_test.go
+++ b/pkg/cache/placeholder_manager_test.go
@@ -256,6 +256,16 @@ func TestCleanUp(t *testing.T) {
                        UID:  "UID-03",
                },
        }
+       pod4 := &v1.Pod{
+               TypeMeta: apis.TypeMeta{
+                       Kind:       "Pod",
+                       APIVersion: "v1",
+               },
+               ObjectMeta: apis.ObjectMeta{
+                       Name: "pod-04",
+                       UID:  "UID-04",
+               },
+       }
        taskID1 := "task01"
        task1 := NewTask(taskID1, app, mockedContext, pod1)
        task1.placeholder = true
@@ -268,12 +278,19 @@ func TestCleanUp(t *testing.T) {
        task3 := NewTask(taskID3, app, mockedContext, pod3)
        task3.placeholder = false
        app.taskMap[taskID3] = task3
+       taskID4 := "task04"
+       task4 := NewTask(taskID4, app, mockedContext, pod4)
+       task4.placeholder = true
+       app.taskMap[taskID4] = task4
        res = app.getNonTerminatedTaskAlias()
-       assert.Equal(t, len(res), 3)
+       assert.Equal(t, len(res), 4)
 
        deletePod := make([]string, 0)
        mockedAPIProvider := client.NewMockedAPIProvider(false)
        mockedAPIProvider.MockDeleteFn(func(pod *v1.Pod) error {
+               if pod.Name == "pod-04" {
+                       return fmt.Errorf("error")
+               }
                deletePod = append(deletePod, pod.Name)
                return nil
        })
@@ -290,11 +307,17 @@ func TestCleanUp(t *testing.T) {
                }
        }
        assert.Equal(t, exist, false)
-       assert.Equal(t, len(placeholderMgr.orphanPods), 0)
+       assert.Equal(t, len(placeholderMgr.orphanPods), 1)
 }
 
 func TestCleanOrphanPlaceholders(t *testing.T) {
        mockedAPIProvider := client.NewMockedAPIProvider(false)
+       mockedAPIProvider.MockDeleteFn(func(pod *v1.Pod) error {
+               if pod.Name == "pod-02" {
+                       return fmt.Errorf("error")
+               }
+               return nil
+       })
        placeholderMgr := NewPlaceholderManager(mockedAPIProvider.GetAPIs())
        pod1 := &v1.Pod{
                TypeMeta: apis.TypeMeta{
@@ -306,10 +329,21 @@ func TestCleanOrphanPlaceholders(t *testing.T) {
                        UID:  "UID-01",
                },
        }
+       pod2 := &v1.Pod{
+               TypeMeta: apis.TypeMeta{
+                       Kind:       "Pod",
+                       APIVersion: "v1",
+               },
+               ObjectMeta: apis.ObjectMeta{
+                       Name: "pod-02",
+                       UID:  "UID-02",
+               },
+       }
        placeholderMgr.orphanPods["task01"] = pod1
-       assert.Equal(t, len(placeholderMgr.orphanPods), 1)
+       placeholderMgr.orphanPods["task02"] = pod2
+       assert.Equal(t, len(placeholderMgr.orphanPods), 2)
        placeholderMgr.cleanOrphanPlaceholders()
-       assert.Equal(t, len(placeholderMgr.orphanPods), 0)
+       assert.Equal(t, len(placeholderMgr.orphanPods), 1)
 }
 
 func TestPlaceholderManagerStartStop(t *testing.T) {
diff --git a/pkg/cache/placeholder_test.go b/pkg/cache/placeholder_test.go
index 553ade1a..cbabd289 100644
--- a/pkg/cache/placeholder_test.go
+++ b/pkg/cache/placeholder_test.go
@@ -110,6 +110,7 @@ func TestNewPlaceholder(t *testing.T) {
                testGroups, map[string]string{constants.AppTagNamespace: 
namespace, constants.AppTagImagePullSecrets: "secret1,secret2"},
                mockedSchedulerAPI)
        app.setTaskGroups(taskGroups)
+       app.setSchedulingParamsDefinition("gangSchedulingStyle=Soft")
        marshalledTaskGroups, err := json.Marshal(taskGroups)
        assert.NilError(t, err, "taskGroups marshalling failed")
        app.setTaskGroupsDefinition(string(marshalledTaskGroups))
@@ -130,12 +131,13 @@ func TestNewPlaceholder(t *testing.T) {
                "labelKey0":                           "labelKeyValue0",
                "labelKey1":                           "labelKeyValue1",
        })
-       assert.Equal(t, len(holder.pod.Annotations), 6, "unexpected number of 
annotations")
+       assert.Equal(t, len(holder.pod.Annotations), 7, "unexpected number of 
annotations")
        assert.Equal(t, 
holder.pod.Annotations[constants.AnnotationTaskGroupName], 
app.taskGroups[0].Name)
        assert.Equal(t, 
holder.pod.Annotations[constants.AnnotationPlaceholderFlag], constants.True)
        assert.Equal(t, holder.pod.Annotations["annotationKey0"], 
"annotationValue0")
        assert.Equal(t, holder.pod.Annotations["annotationKey1"], 
"annotationValue1")
        assert.Equal(t, holder.pod.Annotations["annotationKey2"], 
"annotationValue2")
+       assert.Equal(t, 
holder.pod.Annotations[constants.AnnotationSchedulingPolicyParam], 
"gangSchedulingStyle=Soft")
        var taskGroupsDef []TaskGroup
        err = 
json.Unmarshal([]byte(holder.pod.Annotations[siCommon.DomainYuniKorn+"task-groups"]),
 &taskGroupsDef)
        assert.NilError(t, err, "taskGroupsDef unmarshal failed")


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to