changes in test files

This commit is contained in:
kidddddddddddddddddddddd
2022-10-12 22:11:04 +08:00
parent 121d24cfc7
commit b901ef0f68
7 changed files with 117 additions and 60 deletions

View File

@@ -1262,7 +1262,7 @@ func TestPreFilterStateAddRemovePod(t *testing.T) {
// Add test.addedPod to state1 and verify it is equal to allPodsState.
nodeInfo := mustGetNodeInfo(t, snapshot, test.addedPod.Spec.NodeName)
if err := ipa.AddPod(ctx, cycleState, test.pendingPod, framework.NewPodInfo(test.addedPod), nodeInfo); err != nil {
if err := ipa.AddPod(ctx, cycleState, test.pendingPod, mustNewPodInfo(t, test.addedPod), nodeInfo); err != nil {
t.Errorf("error adding pod to meta: %v", err)
}
@@ -1284,7 +1284,7 @@ func TestPreFilterStateAddRemovePod(t *testing.T) {
}
// Remove the added pod pod and make sure it is equal to the original state.
if err := ipa.RemovePod(context.Background(), cycleState, test.pendingPod, framework.NewPodInfo(test.addedPod), nodeInfo); err != nil {
if err := ipa.RemovePod(context.Background(), cycleState, test.pendingPod, mustNewPodInfo(t, test.addedPod), nodeInfo); err != nil {
t.Errorf("error removing pod from meta: %v", err)
}
if !reflect.DeepEqual(originalState, state) {
@@ -1439,7 +1439,7 @@ func TestGetTPMapMatchingIncomingAffinityAntiAffinity(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
p := plugintesting.SetupPluginWithInformers(ctx, t, New, &config.InterPodAffinityArgs{}, snapshot, nil)
gotAffinityPodsMap, gotAntiAffinityPodsMap := p.(*InterPodAffinity).getIncomingAffinityAntiAffinityCounts(ctx, framework.NewPodInfo(tt.pod), l)
gotAffinityPodsMap, gotAntiAffinityPodsMap := p.(*InterPodAffinity).getIncomingAffinityAntiAffinityCounts(ctx, mustNewPodInfo(t, tt.pod), l)
if !reflect.DeepEqual(gotAffinityPodsMap, tt.wantAffinityPodsMap) {
t.Errorf("getTPMapMatchingIncomingAffinityAntiAffinity() gotAffinityPodsMap = %#v, want %#v", gotAffinityPodsMap, tt.wantAffinityPodsMap)
}
@@ -1458,3 +1458,11 @@ func mustGetNodeInfo(t *testing.T, snapshot *cache.Snapshot, name string) *frame
}
return nodeInfo
}
func mustNewPodInfo(t *testing.T, pod *v1.Pod) *framework.PodInfo {
podInfo, err := framework.NewPodInfo(pod)
if err != nil {
t.Fatal(err)
}
return podInfo
}

View File

@@ -1866,7 +1866,7 @@ func TestPreFilterStateAddPod(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if s := p.AddPod(ctx, cs, tt.preemptor, framework.NewPodInfo(tt.addedPod), nodeInfo); !s.IsSuccess() {
if s := p.AddPod(ctx, cs, tt.preemptor, mustNewPodInfo(t, tt.addedPod), nodeInfo); !s.IsSuccess() {
t.Fatal(s.AsError())
}
state, err := getPreFilterState(cs)
@@ -2188,7 +2188,7 @@ func TestPreFilterStateRemovePod(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if s := p.RemovePod(ctx, cs, tt.preemptor, framework.NewPodInfo(deletedPod), nodeInfo); !s.IsSuccess() {
if s := p.RemovePod(ctx, cs, tt.preemptor, mustNewPodInfo(t, deletedPod), nodeInfo); !s.IsSuccess() {
t.Fatal(s.AsError())
}
@@ -3228,3 +3228,11 @@ func TestPreFilterDisabled(t *testing.T) {
t.Errorf("status does not match: %v, want: %v", gotStatus, wantStatus)
}
}
func mustNewPodInfo(t *testing.T, pod *v1.Pod) *framework.PodInfo {
podInfo, err := framework.NewPodInfo(pod)
if err != nil {
t.Fatal(err)
}
return podInfo
}

View File

@@ -20,6 +20,7 @@ import (
"testing"
"time"
v1 "k8s.io/api/core/v1"
"k8s.io/kubernetes/pkg/scheduler/framework"
st "k8s.io/kubernetes/pkg/scheduler/testing"
)
@@ -38,31 +39,31 @@ func TestLess(t *testing.T) {
{
name: "p1.priority less than p2.priority",
p1: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Priority(lowPriority).Obj()),
PodInfo: mustNewPodInfo(t, st.MakePod().Priority(lowPriority).Obj()),
},
p2: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Priority(highPriority).Obj()),
PodInfo: mustNewPodInfo(t, st.MakePod().Priority(highPriority).Obj()),
},
expected: false, // p2 should be ahead of p1 in the queue
},
{
name: "p1.priority greater than p2.priority",
p1: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Priority(highPriority).Obj()),
PodInfo: mustNewPodInfo(t, st.MakePod().Priority(highPriority).Obj()),
},
p2: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Priority(lowPriority).Obj()),
PodInfo: mustNewPodInfo(t, st.MakePod().Priority(lowPriority).Obj()),
},
expected: true, // p1 should be ahead of p2 in the queue
},
{
name: "equal priority. p1 is added to schedulingQ earlier than p2",
p1: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Priority(highPriority).Obj()),
PodInfo: mustNewPodInfo(t, st.MakePod().Priority(highPriority).Obj()),
Timestamp: t1,
},
p2: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Priority(highPriority).Obj()),
PodInfo: mustNewPodInfo(t, st.MakePod().Priority(highPriority).Obj()),
Timestamp: t2,
},
expected: true, // p1 should be ahead of p2 in the queue
@@ -70,11 +71,11 @@ func TestLess(t *testing.T) {
{
name: "equal priority. p2 is added to schedulingQ earlier than p1",
p1: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Priority(highPriority).Obj()),
PodInfo: mustNewPodInfo(t, st.MakePod().Priority(highPriority).Obj()),
Timestamp: t2,
},
p2: &framework.QueuedPodInfo{
PodInfo: framework.NewPodInfo(st.MakePod().Priority(highPriority).Obj()),
PodInfo: mustNewPodInfo(t, st.MakePod().Priority(highPriority).Obj()),
Timestamp: t1,
},
expected: false, // p2 should be ahead of p1 in the queue
@@ -87,3 +88,11 @@ func TestLess(t *testing.T) {
})
}
}
func mustNewPodInfo(t *testing.T, pod *v1.Pod) *framework.PodInfo {
podInfo, err := framework.NewPodInfo(pod)
if err != nil {
t.Fatal(err)
}
return podInfo
}