Skip to content

Commit

Permalink
Merge pull request #251 from ffromani/deflake-running-test
Browse files Browse the repository at this point in the history
e2e: relax running timeout
  • Loading branch information
ffromani authored Nov 28, 2023
2 parents f0925fd + f9cc31c commit d46345b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion test/e2e/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package e2e
import (
"context"
"fmt"
"time"

"github.com/go-logr/logr"

Expand Down Expand Up @@ -139,7 +140,7 @@ var _ = ginkgo.Describe("[ManifestFlow] Deployer rendering", func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())

ginkgo.By("checking the pod goes running")
e2epods.WaitForPodToBeRunning(cli, testPod.Namespace, testPod.Name)
e2epods.WaitForPodToBeRunning(cli, testPod.Namespace, testPod.Name, 2*time.Minute)
})
})
})
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/positive.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer execution", func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())

ginkgo.By("checking the pod goes running")
e2epods.WaitForPodToBeRunning(cli, testPod.Namespace, testPod.Name)
e2epods.WaitForPodToBeRunning(cli, testPod.Namespace, testPod.Name, 2*time.Minute)
})
})

Expand Down Expand Up @@ -426,9 +426,8 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer execution", func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())

ginkgo.By("checking the pod goes running")
e2epods.WaitForPodToBeRunning(cli, testPod.Namespace, testPod.Name)
e2epods.WaitForPodToBeRunning(cli, testPod.Namespace, testPod.Name, 2*time.Minute)
})

})
})
})
Expand Down
20 changes: 14 additions & 6 deletions test/e2e/utils/pods/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package pods

import (
"context"
"errors"
"fmt"
"regexp"
"time"
Expand Down Expand Up @@ -68,9 +69,10 @@ func GuaranteedSleeperPod(namespace, schedulerName string) *corev1.Pod {
}
}

func WaitForPodToBeRunning(cli *kubernetes.Clientset, podNamespace, podName string) *corev1.Pod {
func WaitForPodToBeRunning(cli *kubernetes.Clientset, podNamespace, podName string, timeout time.Duration) *corev1.Pod {
var err error
var pod *corev1.Pod
startTime := time.Now()
gomega.EventuallyWithOffset(1, func() error {
pod, err = cli.CoreV1().Pods(podNamespace).Get(context.TODO(), podName, metav1.GetOptions{})
if err != nil {
Expand All @@ -80,18 +82,21 @@ func WaitForPodToBeRunning(cli *kubernetes.Clientset, podNamespace, podName stri
case corev1.PodFailed, corev1.PodSucceeded:
return fmt.Errorf("pod %q status %q which is unexpected", podName, pod.Status.Phase)
case corev1.PodRunning:
fmt.Fprintf(ginkgo.GinkgoWriter, "Pod %q is running!\n", podName)
fmt.Fprintf(ginkgo.GinkgoWriter, "Pod %q is running! (took %v)\n", podName, time.Since(startTime))
return nil
}
return fmt.Errorf("pod %q status %q, waiting for it to be Running (with Ready = true)", podName, pod.Status.Phase)
}, 1*time.Minute, 15*time.Second).ShouldNot(gomega.HaveOccurred())
msg := fmt.Sprintf("pod %q status %q, waiting for it to be Running (with Ready = true)", podName, pod.Status.Phase)
fmt.Fprintln(ginkgo.GinkgoWriter, msg)
return errors.New(msg)
}, timeout, 10*time.Second).ShouldNot(gomega.HaveOccurred())
return pod
}

func WaitPodsToBeRunningByRegex(pattern string) {
cs, err := clientutil.New()
gomega.Expect(err).ToNot(gomega.HaveOccurred())

startTime := time.Now()
gomega.EventuallyWithOffset(1, func() error {
pods, err := GetByRegex(cs, fmt.Sprintf("%s-*", pattern))
if err != nil {
Expand All @@ -103,11 +108,14 @@ func WaitPodsToBeRunningByRegex(pattern string) {

for _, pod := range pods {
if pod.Status.Phase != corev1.PodRunning {
return fmt.Errorf("pod %q is not in %v state", pod.Name, corev1.PodRunning)
msg := fmt.Sprintf("pod %q is not in %v state", pod.Name, corev1.PodRunning)
fmt.Println(ginkgo.GinkgoWriter, msg)
return errors.New(msg)
}
}
fmt.Fprintf(ginkgo.GinkgoWriter, "all pods running! (took %v)\n", time.Since(startTime))
return nil
}, 1*time.Minute, 15*time.Second).ShouldNot(gomega.HaveOccurred())
}, 1*time.Minute, 10*time.Second).ShouldNot(gomega.HaveOccurred())
}

func GetByRegex(cs client.Client, reg string) ([]*corev1.Pod, error) {
Expand Down

0 comments on commit d46345b

Please sign in to comment.