Skip to content

Commit

Permalink
test dedicated for StrictFIFO
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Wang <wangqingcan1990@gmail.com>
  • Loading branch information
denkensk committed Apr 30, 2022
1 parent c622564 commit 528f3e5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/util/testing/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ func (w *WorkloadWrapper) PriorityClass(priorityClassName string) *WorkloadWrapp
return w
}

func (w *WorkloadWrapper) Priority(priority *int32) *WorkloadWrapper {
w.Spec.Priority = priority
return w
}

// AdmissionWrapper wraps an Admission
type AdmissionWrapper struct{ kueue.Admission }

Expand Down
19 changes: 19 additions & 0 deletions test/integration/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,25 @@ func ExpectWorkloadsToBePending(ctx context.Context, k8sClient client.Client, wl
}, Timeout, Interval).Should(gomega.Equal(len(wls)), "Not enough workloads are pending")
}

func ExpectWorkloadsToBeInadmissible(ctx context.Context, k8sClient client.Client, wls ...*kueue.Workload) {
gomega.EventuallyWithOffset(1, func() int {
inadmissible := 0
var updatedWorkload kueue.Workload
for _, wl := range wls {
gomega.ExpectWithOffset(1, k8sClient.Get(ctx, client.ObjectKeyFromObject(wl), &updatedWorkload)).To(gomega.Succeed())
idx := workload.FindConditionIndex(&updatedWorkload.Status, kueue.WorkloadAdmitted)
if idx == -1 {
continue
}
cond := updatedWorkload.Status.Conditions[idx]
if cond.Status == corev1.ConditionFalse && cond.Reason == "Inadmissible" && wl.Spec.Admission == nil {
inadmissible++
}
}
return inadmissible
}, Timeout, Interval).Should(gomega.Equal(len(wls)), "Not enough workloads are inadmissible")
}

func UpdateWorkloadStatus(ctx context.Context, k8sClient client.Client, wl *kueue.Workload, update func(*kueue.Workload)) {
gomega.EventuallyWithOffset(1, func() error {
var updatedWl kueue.Workload
Expand Down
33 changes: 33 additions & 0 deletions test/integration/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,37 @@ var _ = ginkgo.Describe("Scheduler", func() {
framework.ExpectWorkloadsToBeAdmitted(ctx, k8sClient, prodBEClusterQ.Name, wl1)
framework.ExpectWorkloadsToBeAdmitted(ctx, k8sClient, devBEClusterQ.Name, wl2)
})

ginkgo.It("Should schedule workloads by their priority strictly in StrictFIFO", func() {
strictFIFOClusterQ := testing.MakeClusterQueue("strict-fifo-cq").
QueueingStrategy(kueue.StrictFIFO).
Resource(testing.MakeResource(corev1.ResourceCPU).
Flavor(testing.MakeFlavor(onDemandFlavor.Name,
"5").Max("5").Obj()).
Obj()).
Obj()
gomega.Expect(k8sClient.Create(ctx, strictFIFOClusterQ)).Should(gomega.Succeed())
defer func() {
gomega.Expect(framework.DeleteClusterQueue(ctx, k8sClient, strictFIFOClusterQ)).Should(gomega.Succeed())
}()

strictFIFOQueue := testing.MakeQueue("strict-fifo-q", ns.Name).ClusterQueue(strictFIFOClusterQ.Name).Obj()
ginkgo.By("Creating workloads")
wl1 := testing.MakeWorkload("wl1", ns.Name).Queue(strictFIFOQueue.
Name).Request(corev1.ResourceCPU, "2").Priority(pointer.Int32(100)).Obj()
gomega.Expect(k8sClient.Create(ctx, wl1)).Should(gomega.Succeed())
wl2 := testing.MakeWorkload("wl2", ns.Name).Queue(strictFIFOQueue.
Name).Request(corev1.ResourceCPU, "5").Priority(pointer.Int32(10)).Obj()
gomega.Expect(k8sClient.Create(ctx, wl2)).Should(gomega.Succeed())
// wl3 can't be scheduled before wl2 even it can be scheduled successfully.
wl3 := testing.MakeWorkload("wl3", ns.Name).Queue(strictFIFOQueue.
Name).Request(corev1.ResourceCPU, "1").Priority(pointer.Int32(1)).Obj()
gomega.Expect(k8sClient.Create(ctx, wl3)).Should(gomega.Succeed())

gomega.Expect(k8sClient.Create(ctx, strictFIFOQueue)).Should(gomega.Succeed())

framework.ExpectWorkloadsToBeAdmitted(ctx, k8sClient, strictFIFOClusterQ.Name, wl1)
framework.ExpectWorkloadsToBePending(ctx, k8sClient, wl2)
framework.ExpectWorkloadsToBeInadmissible(ctx, k8sClient, wl3)
})
})

0 comments on commit 528f3e5

Please sign in to comment.