Skip to content

Commit fc1824f

Browse files
authored
Merge pull request kubernetes#86348 from soltysh/issue86179
Split cronjob tests, so they don't interfere
2 parents 4a62b3a + 667aaf3 commit fc1824f

File tree

1 file changed

+60
-61
lines changed

1 file changed

+60
-61
lines changed

test/e2e/apps/cronjob.go

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -229,72 +229,71 @@ var _ = SIGDescribe("CronJob", func() {
229229
framework.ExpectNoError(err, "Failed to remove %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name)
230230
})
231231

232-
// cleanup of successful/failed finished jobs, with successfulJobsHistoryLimit and failedJobsHistoryLimit
233-
ginkgo.It("should delete successful/failed finished jobs with limit of one job [Flaky]", func() {
234-
235-
testCases := []struct {
236-
description string
237-
command []string
238-
successLimit int32
239-
failedLimit int32
240-
}{
241-
{
242-
description: "successful-jobs-history-limit",
243-
command: successCommand,
244-
successLimit: 1, // keep one successful job
245-
failedLimit: 0, // keep none failed job
246-
},
247-
{
248-
description: "failed-jobs-history-limit",
249-
command: failureCommand,
250-
successLimit: 0, // keep none succcessful job
251-
failedLimit: 1, // keep one failed job
252-
},
253-
}
232+
// cleanup of successful finished jobs, with limit of one successful job
233+
ginkgo.It("should delete successful finished jobs with limit of one successful job", func() {
234+
ginkgo.By("Creating an AllowConcurrent cronjob with custom history limit")
235+
successLimit := int32(1)
236+
failedLimit := int32(0)
237+
cronJob := newTestCronJob("successful-jobs-history-limit", "*/1 * * * ?", batchv1beta1.AllowConcurrent,
238+
successCommand, &successLimit, &failedLimit)
239+
240+
ensureHistoryLimits(f.ClientSet, f.Namespace.Name, cronJob)
241+
})
254242

255-
for _, t := range testCases {
256-
ginkgo.By(fmt.Sprintf("Creating a AllowConcurrent cronjob with custom %s", t.description))
257-
cronJob := newTestCronJob(t.description, "*/1 * * * ?", batchv1beta1.AllowConcurrent,
258-
t.command, &t.successLimit, &t.failedLimit)
259-
cronJob, err := createCronJob(f.ClientSet, f.Namespace.Name, cronJob)
260-
framework.ExpectNoError(err, "Failed to create allowconcurrent cronjob with custom history limits in namespace %s", f.Namespace.Name)
261-
262-
// Job is going to complete instantly: do not check for an active job
263-
// as we are most likely to miss it
264-
265-
ginkgo.By("Ensuring a finished job exists")
266-
err = waitForAnyFinishedJob(f.ClientSet, f.Namespace.Name)
267-
framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists in namespace %s", f.Namespace.Name)
268-
269-
ginkgo.By("Ensuring a finished job exists by listing jobs explicitly")
270-
jobs, err := f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
271-
framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists by listing jobs explicitly in namespace %s", f.Namespace.Name)
272-
activeJobs, finishedJobs := filterActiveJobs(jobs)
273-
if len(finishedJobs) != 1 {
274-
framework.Logf("Expected one finished job in namespace %s; activeJobs=%v; finishedJobs=%v", f.Namespace.Name, activeJobs, finishedJobs)
275-
framework.ExpectEqual(len(finishedJobs), 1)
276-
}
243+
// cleanup of failed finished jobs, with limit of one failed job
244+
ginkgo.It("should delete failed finished jobs with limit of one job", func() {
245+
ginkgo.By("Creating an AllowConcurrent cronjob with custom history limit")
246+
successLimit := int32(0)
247+
failedLimit := int32(1)
248+
cronJob := newTestCronJob("failed-jobs-history-limit", "*/1 * * * ?", batchv1beta1.AllowConcurrent,
249+
failureCommand, &successLimit, &failedLimit)
277250

278-
// Job should get deleted when the next job finishes the next minute
279-
ginkgo.By("Ensuring this job and its pods does not exist anymore")
280-
err = waitForJobToDisappear(f.ClientSet, f.Namespace.Name, finishedJobs[0])
281-
framework.ExpectNoError(err, "Failed to ensure that job does not exists anymore in namespace %s", f.Namespace.Name)
282-
err = waitForJobsPodToDisappear(f.ClientSet, f.Namespace.Name, finishedJobs[0])
283-
framework.ExpectNoError(err, "Failed to ensure that pods for job does not exists anymore in namespace %s", f.Namespace.Name)
284-
285-
ginkgo.By("Ensuring there is 1 finished job by listing jobs explicitly")
286-
jobs, err = f.ClientSet.BatchV1().Jobs(f.Namespace.Name).List(metav1.ListOptions{})
287-
framework.ExpectNoError(err, "Failed to ensure there is one finished job by listing job explicitly in namespace %s", f.Namespace.Name)
288-
_, finishedJobs = filterActiveJobs(jobs)
289-
framework.ExpectEqual(len(finishedJobs), 1)
290-
291-
ginkgo.By("Removing cronjob")
292-
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
293-
framework.ExpectNoError(err, "Failed to remove the %s cronjob in namespace %s", cronJob.Name, f.Namespace.Name)
294-
}
251+
ensureHistoryLimits(f.ClientSet, f.Namespace.Name, cronJob)
295252
})
253+
296254
})
297255

256+
func ensureHistoryLimits(c clientset.Interface, ns string, cronJob *batchv1beta1.CronJob) {
257+
cronJob, err := createCronJob(c, ns, cronJob)
258+
framework.ExpectNoError(err, "Failed to create allowconcurrent cronjob with custom history limits in namespace %s", ns)
259+
260+
// Job is going to complete instantly: do not check for an active job
261+
// as we are most likely to miss it
262+
263+
ginkgo.By("Ensuring a finished job exists")
264+
err = waitForAnyFinishedJob(c, ns)
265+
framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists in namespace %s", ns)
266+
267+
ginkgo.By("Ensuring a finished job exists by listing jobs explicitly")
268+
jobs, err := c.BatchV1().Jobs(ns).List(metav1.ListOptions{})
269+
framework.ExpectNoError(err, "Failed to ensure a finished cronjob exists by listing jobs explicitly in namespace %s", ns)
270+
activeJobs, finishedJobs := filterActiveJobs(jobs)
271+
if len(finishedJobs) != 1 {
272+
framework.Logf("Expected one finished job in namespace %s; activeJobs=%v; finishedJobs=%v", ns, activeJobs, finishedJobs)
273+
framework.ExpectEqual(len(finishedJobs), 1)
274+
}
275+
276+
// Job should get deleted when the next job finishes the next minute
277+
ginkgo.By("Ensuring this job and its pods does not exist anymore")
278+
err = waitForJobToDisappear(c, ns, finishedJobs[0])
279+
framework.ExpectNoError(err, "Failed to ensure that job does not exists anymore in namespace %s", ns)
280+
err = waitForJobsPodToDisappear(c, ns, finishedJobs[0])
281+
framework.ExpectNoError(err, "Failed to ensure that pods for job does not exists anymore in namespace %s", ns)
282+
283+
ginkgo.By("Ensuring there is 1 finished job by listing jobs explicitly")
284+
jobs, err = c.BatchV1().Jobs(ns).List(metav1.ListOptions{})
285+
framework.ExpectNoError(err, "Failed to ensure there is one finished job by listing job explicitly in namespace %s", ns)
286+
activeJobs, finishedJobs = filterActiveJobs(jobs)
287+
if len(finishedJobs) != 1 {
288+
framework.Logf("Expected one finished job in namespace %s; activeJobs=%v; finishedJobs=%v", ns, activeJobs, finishedJobs)
289+
framework.ExpectEqual(len(finishedJobs), 1)
290+
}
291+
292+
ginkgo.By("Removing cronjob")
293+
err = deleteCronJob(c, ns, cronJob.Name)
294+
framework.ExpectNoError(err, "Failed to remove the %s cronjob in namespace %s", cronJob.Name, ns)
295+
}
296+
298297
// newTestCronJob returns a cronjob which does one of several testing behaviors.
299298
func newTestCronJob(name, schedule string, concurrencyPolicy batchv1beta1.ConcurrencyPolicy,
300299
command []string, successfulJobsHistoryLimit *int32, failedJobsHistoryLimit *int32) *batchv1beta1.CronJob {

0 commit comments

Comments
 (0)