Wait for events instead of just checking them in cronjob e2e
This commit is contained in:
		@@ -180,8 +180,8 @@ var _ = SIGDescribe("CronJob", func() {
 | 
				
			|||||||
		Expect(err).NotTo(HaveOccurred())
 | 
							Expect(err).NotTo(HaveOccurred())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		By("Ensuring no unexpected event has happened")
 | 
							By("Ensuring no unexpected event has happened")
 | 
				
			||||||
		err = checkNoEventWithReason(f.ClientSet, f.Namespace.Name, cronJob.Name, []string{"MissingJob", "UnexpectedJob"})
 | 
							err = waitForEventWithReason(f.ClientSet, f.Namespace.Name, cronJob.Name, []string{"MissingJob", "UnexpectedJob"})
 | 
				
			||||||
		Expect(err).NotTo(HaveOccurred())
 | 
							Expect(err).To(HaveOccurred())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		By("Removing cronjob")
 | 
							By("Removing cronjob")
 | 
				
			||||||
		err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
 | 
							err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
 | 
				
			||||||
@@ -219,8 +219,8 @@ var _ = SIGDescribe("CronJob", func() {
 | 
				
			|||||||
		Expect(err).NotTo(HaveOccurred())
 | 
							Expect(err).NotTo(HaveOccurred())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		By("Ensuring MissingJob event has occurred")
 | 
							By("Ensuring MissingJob event has occurred")
 | 
				
			||||||
		err = checkNoEventWithReason(f.ClientSet, f.Namespace.Name, cronJob.Name, []string{"MissingJob"})
 | 
							err = waitForEventWithReason(f.ClientSet, f.Namespace.Name, cronJob.Name, []string{"MissingJob"})
 | 
				
			||||||
		Expect(err).To(HaveOccurred())
 | 
							Expect(err).NotTo(HaveOccurred())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		By("Removing cronjob")
 | 
							By("Removing cronjob")
 | 
				
			||||||
		err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
 | 
							err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name)
 | 
				
			||||||
@@ -426,24 +426,26 @@ func waitForAnyFinishedJob(c clientset.Interface, ns string) error {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// checkNoEventWithReason checks no events with a reason within a list has occurred
 | 
					// waitForEventWithReason waits for events with a reason within a list has occurred
 | 
				
			||||||
func checkNoEventWithReason(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) {
 | 
				
			||||||
		sj, err := c.BatchV1beta1().CronJobs(ns).Get(cronJobName, metav1.GetOptions{})
 | 
							sj, err := c.BatchV1beta1().CronJobs(ns).Get(cronJobName, metav1.GetOptions{})
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
		return fmt.Errorf("Error in getting cronjob %s/%s: %v", ns, cronJobName, err)
 | 
								return false, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		events, err := c.CoreV1().Events(ns).Search(legacyscheme.Scheme, sj)
 | 
							events, err := c.CoreV1().Events(ns).Search(legacyscheme.Scheme, sj)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
		return fmt.Errorf("Error in listing events: %s", err)
 | 
								return false, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		for _, e := range events.Items {
 | 
							for _, e := range events.Items {
 | 
				
			||||||
			for _, reason := range reasons {
 | 
								for _, reason := range reasons {
 | 
				
			||||||
				if e.Reason == reason {
 | 
									if e.Reason == reason {
 | 
				
			||||||
				return fmt.Errorf("Found event with reason %s: %#v", reason, e)
 | 
										return true, nil
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	return nil
 | 
							return false, nil
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// filterNotDeletedJobs returns the job list without any jobs that are pending
 | 
					// filterNotDeletedJobs returns the job list without any jobs that are pending
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user