Skip to content

Commit

Permalink
eventually updates (#215)
Browse files Browse the repository at this point in the history
* eventaully updates

* pr comments

* remove shouldSucceed from updates as we have no fail cases

* fmt
  • Loading branch information
kannon92 authored Jun 29, 2023
1 parent 668dc31 commit d067ea4
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions test/integration/controller/jobset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ var _ = ginkgo.Describe("JobSet validation", func() {
// jobSetUpdate contains the mutations to perform on the jobset and the
// checks to perform afterwards.
type jobSetUpdate struct {
fn func(*jobset.JobSet)
shouldSucceed bool
fn func(*jobset.JobSet)
}

type testCase struct {
makeJobSet func(*corev1.Namespace) *testing.JobSetWrapper
jobSetCreationShouldSucceed bool
updates []*jobSetUpdate
makeJobSet func(*corev1.Namespace) *testing.JobSetWrapper
updates []*jobSetUpdate
}

ginkgo.DescribeTable("JobSet validation during creation and updates",
Expand All @@ -66,6 +64,7 @@ var _ = ginkgo.Describe("JobSet validation", func() {
GenerateName: "jobset-ns-",
},
}

gomega.Expect(k8sClient.Create(ctx, ns)).To(gomega.Succeed())

defer func() {
Expand All @@ -76,40 +75,33 @@ var _ = ginkgo.Describe("JobSet validation", func() {
ginkgo.By("creating jobset")
js := tc.makeJobSet(ns).Obj()

// If we are expected a validation error creating the jobset, end the test early.
if !tc.jobSetCreationShouldSucceed {
ginkgo.By("checking that jobset creation fails")
gomega.Expect(k8sClient.Create(ctx, js)).To(gomega.Not(gomega.Succeed()))
return
}

// Verify jobset created successfully.
ginkgo.By("checking that jobset creation succeeds")
gomega.Expect(k8sClient.Create(ctx, js)).To(gomega.Succeed())
gomega.Eventually(func() error {
return k8sClient.Create(ctx, js)
}, timeout, interval).Should(gomega.Succeed())

// Perform updates to the jobset and verify the validation is working correctly.
for _, update := range tc.updates {

// Update jobset if specified.
if update.fn != nil {
update.fn(js)

// If we are expecting a validation error, we can skip the rest of the checks.
if !update.shouldSucceed {
gomega.Expect(k8sClient.Update(ctx, js)).To(gomega.Not(gomega.Succeed()))
continue
}
// Verify a valid jobset update succeeded.
gomega.Expect(k8sClient.Update(ctx, js)).To(gomega.Succeed())
gomega.Eventually(func() error {
var jsGet jobset.JobSet
if err := k8sClient.Get(ctx, types.NamespacedName{Name: js.Name, Namespace: js.Namespace}, &jsGet); err != nil {
return err
}
update.fn(&jsGet)
return k8sClient.Update(ctx, &jsGet)
}, timeout, interval).Should(gomega.Succeed())
}
}
},
ginkgo.Entry("setting suspend is allowed", &testCase{
makeJobSet: testJobSet,
jobSetCreationShouldSucceed: true,
makeJobSet: testJobSet,
updates: []*jobSetUpdate{
{
shouldSucceed: true,
fn: func(js *jobset.JobSet) {
js.Spec.Suspend = pointer.Bool(true)
},
Expand Down Expand Up @@ -160,7 +152,9 @@ var _ = ginkgo.Describe("JobSet controller", func() {

// Verify jobset created successfully.
ginkgo.By(fmt.Sprintf("creating jobSet %s/%s", js.Name, js.Namespace))
gomega.Expect(k8sClient.Create(ctx, js)).To(gomega.Succeed())
gomega.Eventually(func() error {
return k8sClient.Create(ctx, js)
}, timeout, interval).Should(gomega.Succeed())

ginkgo.By("checking all jobs were created successfully")
gomega.Eventually(testutil.NumJobs, timeout, interval).WithArguments(ctx, k8sClient, js).Should(gomega.Equal(testutil.NumExpectedJobs(js)))
Expand All @@ -175,7 +169,7 @@ var _ = ginkgo.Describe("JobSet controller", func() {
} else if up.jobUpdateFn != nil {
// Fetch updated job objects so we always have the latest resource versions to perform mutations on.
var jobList batchv1.JobList
gomega.Expect(k8sClient.List(ctx, &jobList, client.InNamespace(js.Namespace))).To(gomega.Succeed())
gomega.Expect(k8sClient.List(ctx, &jobList, client.InNamespace(js.Namespace))).Should(gomega.Succeed())
gomega.Expect(len(jobList.Items)).To(gomega.Equal(testutil.NumExpectedJobs(js)))
up.jobUpdateFn(&jobList)
}
Expand Down

0 comments on commit d067ea4

Please sign in to comment.