mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #70206 from runcom/fix-cronjob-e2e
test/e2e/apps: fix race in cronjob test
This commit is contained in:
commit
9ed206e3b9
@ -214,8 +214,8 @@ var _ = SIGDescribe("CronJob", func() {
|
|||||||
Expect(err).To(HaveOccurred())
|
Expect(err).To(HaveOccurred())
|
||||||
Expect(errors.IsNotFound(err)).To(BeTrue())
|
Expect(errors.IsNotFound(err)).To(BeTrue())
|
||||||
|
|
||||||
By("Ensuring there are no active jobs in the cronjob")
|
By("Ensuring the job is not in the cronjob active list")
|
||||||
err = waitForNoJobs(f.ClientSet, f.Namespace.Name, cronJob.Name, true)
|
err = waitForJobNotActive(f.ClientSet, f.Namespace.Name, cronJob.Name, job.Name)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
By("Ensuring MissingJob event has occurred")
|
By("Ensuring MissingJob event has occurred")
|
||||||
@ -336,7 +336,7 @@ func deleteCronJob(c clientset.Interface, ns, name string) error {
|
|||||||
// Wait for at least given amount of active jobs.
|
// Wait for at least given amount of active jobs.
|
||||||
func waitForActiveJobs(c clientset.Interface, ns, cronJobName string, active int) error {
|
func waitForActiveJobs(c clientset.Interface, ns, cronJobName string, active int) error {
|
||||||
return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) {
|
return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) {
|
||||||
curr, err := c.BatchV1beta1().CronJobs(ns).Get(cronJobName, metav1.GetOptions{})
|
curr, err := getCronJob(c, ns, cronJobName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ func waitForActiveJobs(c clientset.Interface, ns, cronJobName string, active int
|
|||||||
// empty after the timeout.
|
// empty after the timeout.
|
||||||
func waitForNoJobs(c clientset.Interface, ns, jobName string, failIfNonEmpty bool) error {
|
func waitForNoJobs(c clientset.Interface, ns, jobName string, failIfNonEmpty bool) error {
|
||||||
return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) {
|
return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) {
|
||||||
curr, err := c.BatchV1beta1().CronJobs(ns).Get(jobName, metav1.GetOptions{})
|
curr, err := getCronJob(c, ns, jobName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -363,6 +363,23 @@ func waitForNoJobs(c clientset.Interface, ns, jobName string, failIfNonEmpty boo
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait till a given job actually goes away from the Active list for a given cronjob
|
||||||
|
func waitForJobNotActive(c clientset.Interface, ns, cronJobName, jobName string) error {
|
||||||
|
return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) {
|
||||||
|
curr, err := getCronJob(c, ns, cronJobName)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, j := range curr.Status.Active {
|
||||||
|
if j.Name == jobName {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for a job to not exist by listing jobs explicitly.
|
// Wait for a job to not exist by listing jobs explicitly.
|
||||||
func waitForJobNotExist(c clientset.Interface, ns string, targetJob *batchv1.Job) error {
|
func waitForJobNotExist(c clientset.Interface, ns string, targetJob *batchv1.Job) error {
|
||||||
return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) {
|
return wait.Poll(framework.Poll, cronJobTimeout, func() (bool, error) {
|
||||||
@ -429,7 +446,7 @@ func waitForAnyFinishedJob(c clientset.Interface, ns string) error {
|
|||||||
// waitForEventWithReason waits for events with a reason within a list has occurred
|
// waitForEventWithReason waits for events with a reason within a list has occurred
|
||||||
func waitForEventWithReason(c clientset.Interface, ns, cronJobName string, reasons []string) error {
|
func waitForEventWithReason(c clientset.Interface, ns, cronJobName string, reasons []string) error {
|
||||||
return wait.Poll(framework.Poll, 30*time.Second, func() (bool, error) {
|
return wait.Poll(framework.Poll, 30*time.Second, func() (bool, error) {
|
||||||
sj, err := c.BatchV1beta1().CronJobs(ns).Get(cronJobName, metav1.GetOptions{})
|
sj, err := getCronJob(c, ns, cronJobName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user