Skip to content

Commit

Permalink
TAS: add e2e tests for rank ordering for Job (#3584)
Browse files Browse the repository at this point in the history
  • Loading branch information
mimowo authored Nov 19, 2024
1 parent 5a6a680 commit ec42d93
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/e2e/tas/tas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import (

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

kueuealpha "sigs.k8s.io/kueue/apis/kueue/v1alpha1"
kueue "sigs.k8s.io/kueue/apis/kueue/v1beta1"
Expand Down Expand Up @@ -247,5 +249,63 @@ var _ = ginkgo.Describe("TopologyAwareScheduling", func() {
}, util.LongTimeout, util.Interval).Should(gomega.Succeed())
})
})

ginkgo.It("Should place pods based on the ranks-ordering", func() {
numPods := 4
sampleJob := testingjob.MakeJob("ranks-job", ns.Name).
Queue(localQueue.Name).
Parallelism(int32(numPods)).
Completions(int32(numPods)).
Indexed(true).
Request(extraResource, "1").
Limit(extraResource, "1").
Obj()
sampleJob = (&testingjob.JobWrapper{Job: *sampleJob}).
PodAnnotation(kueuealpha.PodSetRequiredTopologyAnnotation, topologyLevelBlock).
Image(util.E2eTestSleepImage, []string{"60s"}).
Obj()
gomega.Expect(k8sClient.Create(ctx, sampleJob)).Should(gomega.Succeed())

ginkgo.By("Job is unsuspended, and has all Pods active and ready", func() {
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(sampleJob), sampleJob)).To(gomega.Succeed())
g.Expect(sampleJob.Spec.Suspend).Should(gomega.Equal(ptr.To(false)))
}, util.LongTimeout, util.Interval).Should(gomega.Succeed())
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(sampleJob), sampleJob)).To(gomega.Succeed())
g.Expect(sampleJob.Status.Active).Should(gomega.Equal(int32(numPods)))
}, util.LongTimeout, util.Interval).Should(gomega.Succeed())
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(sampleJob), sampleJob)).To(gomega.Succeed())
g.Expect(sampleJob.Status.Ready).Should(gomega.Equal(ptr.To[int32](int32(numPods))))
}, util.LongTimeout, util.Interval).Should(gomega.Succeed())
})

pods := &corev1.PodList{}
ginkgo.By("ensure all pods are scheduled", func() {
gomega.Eventually(func(g gomega.Gomega) {
gomega.Expect(k8sClient.List(ctx, pods, client.InNamespace(ns.Name),
client.MatchingLabels(sampleJob.Spec.Selector.MatchLabels))).To(gomega.Succeed())
g.Expect(pods.Items).Should(gomega.HaveLen(numPods))
}, util.LongTimeout, util.Interval).Should(gomega.Succeed())
})

ginkgo.By("verify the assignment of pods are as expected with rank-based ordering", func() {
gomega.Expect(k8sClient.List(ctx, pods, client.InNamespace(ns.Name),
client.MatchingLabels(sampleJob.Spec.Selector.MatchLabels))).To(gomega.Succeed())
gotAssignment := make(map[string]string, numPods)
for _, pod := range pods.Items {
index := pod.Labels[batchv1.JobCompletionIndexAnnotation]
gotAssignment[index] = pod.Spec.NodeName
}
wantAssignment := map[string]string{
"0": "kind-worker",
"1": "kind-worker2",
"2": "kind-worker3",
"3": "kind-worker4",
}
gomega.Expect(wantAssignment).Should(gomega.BeComparableTo(gotAssignment))
})
})
})
})

0 comments on commit ec42d93

Please sign in to comment.