Skip to content

Commit 31d4575

Browse files
authored
Pass context to the utility methods in e2e tests (#516)
1 parent 5f1914b commit 31d4575

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

test/e2e/mpi_job_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ var _ = ginkgo.Describe("MPIJob", func() {
128128
mpiJob.Spec.RunPolicy.Suspend = pointer.Bool(true)
129129
})
130130
ginkgo.It("should not create pods when suspended and succeed when resumed", func() {
131-
mpiJob := createJob(mpiJob)
132-
133131
ctx := context.Background()
132+
mpiJob := createJob(ctx, mpiJob)
133+
134134
ginkgo.By("verifying there are no pods (neither launcher nor pods) running for the suspended MPIJob")
135135
pods, err := k8sClient.CoreV1().Pods(mpiJob.Namespace).List(ctx, metav1.ListOptions{})
136136
gomega.Expect(err).ToNot(gomega.HaveOccurred())
137137
gomega.Expect(pods.Items).To(gomega.HaveLen(0))
138138

139-
mpiJob = resumeJob(mpiJob)
140-
mpiJob = waitForCompletion(mpiJob)
139+
mpiJob = resumeJob(ctx, mpiJob)
140+
mpiJob = waitForCompletion(ctx, mpiJob)
141141
expectConditionToBeTrue(mpiJob, kubeflow.JobSucceeded)
142142
})
143143
})
@@ -231,8 +231,7 @@ var _ = ginkgo.Describe("MPIJob", func() {
231231
})
232232
})
233233

234-
func resumeJob(mpiJob *kubeflow.MPIJob) *kubeflow.MPIJob {
235-
ctx := context.Background()
234+
func resumeJob(ctx context.Context, mpiJob *kubeflow.MPIJob) *kubeflow.MPIJob {
236235
mpiJob.Spec.RunPolicy.Suspend = pointer.Bool(false)
237236
ginkgo.By("Resuming MPIJob")
238237
mpiJob, err := mpiClient.KubeflowV2beta1().MPIJobs(mpiJob.Namespace).Update(ctx, mpiJob, metav1.UpdateOptions{})
@@ -241,21 +240,20 @@ func resumeJob(mpiJob *kubeflow.MPIJob) *kubeflow.MPIJob {
241240
}
242241

243242
func createJobAndWaitForCompletion(mpiJob *kubeflow.MPIJob) *kubeflow.MPIJob {
244-
mpiJob = createJob(mpiJob)
245-
return waitForCompletion(mpiJob)
243+
ctx := context.Background()
244+
mpiJob = createJob(ctx, mpiJob)
245+
return waitForCompletion(ctx, mpiJob)
246246
}
247247

248-
func createJob(mpiJob *kubeflow.MPIJob) *kubeflow.MPIJob {
249-
ctx := context.Background()
248+
func createJob(ctx context.Context, mpiJob *kubeflow.MPIJob) *kubeflow.MPIJob {
250249
ginkgo.By("Creating MPIJob")
251250
mpiJob, err := mpiClient.KubeflowV2beta1().MPIJobs(mpiJob.Namespace).Create(ctx, mpiJob, metav1.CreateOptions{})
252251
gomega.Expect(err).ToNot(gomega.HaveOccurred())
253252
return mpiJob
254253
}
255254

256-
func waitForCompletion(mpiJob *kubeflow.MPIJob) *kubeflow.MPIJob {
255+
func waitForCompletion(ctx context.Context, mpiJob *kubeflow.MPIJob) *kubeflow.MPIJob {
257256
var err error
258-
ctx := context.Background()
259257

260258
ginkgo.By("Waiting for MPIJob to finish")
261259
err = wait.Poll(waitInterval, foreverTimeout, func() (bool, error) {

0 commit comments

Comments
 (0)