Skip to content

Commit

Permalink
Adjust base timeouts for integration and E2E tests (#1919)
Browse files Browse the repository at this point in the history
Change-Id: I4269e45313d0d058bec1157f6813eb0f425a6289
  • Loading branch information
alculquicondor committed Mar 26, 2024
1 parent 70e1b52 commit 69385f4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
36 changes: 6 additions & 30 deletions test/e2e/singlecluster/pod_test.go
Expand Up @@ -237,21 +237,9 @@ var _ = ginkgo.Describe("Pod groups", func() {
gomega.Expect(k8sClient.Create(ctx, excess)).To(gomega.Succeed())
})
ginkgo.By("Use events to observe the excess pods are getting stopped", func() {
preemptedPods := sets.New[types.NamespacedName]()
gomega.Eventually(func(g gomega.Gomega) sets.Set[types.NamespacedName] {
select {
case evt, ok := <-eventWatcher.ResultChan():
g.Expect(ok).To(gomega.BeTrue())
event, ok := evt.Object.(*corev1.Event)
g.Expect(ok).To(gomega.BeTrue())
if event.InvolvedObject.Namespace == ns.Name && event.Reason == "ExcessPodDeleted" {
objKey := types.NamespacedName{Namespace: event.InvolvedObject.Namespace, Name: event.InvolvedObject.Name}
preemptedPods.Insert(objKey)
}
default:
}
return preemptedPods
}, util.Timeout, util.Interval).Should(gomega.Equal(excessPods))
util.ExpectEventsForObjects(eventWatcher, excessPods, func(e *corev1.Event) bool {
return e.InvolvedObject.Namespace == ns.Name && e.Reason == "ExcessPodDeleted"
})
})
ginkgo.By("Verify the excess pod is deleted", func() {
gomega.Eventually(func() error {
Expand Down Expand Up @@ -374,21 +362,9 @@ var _ = ginkgo.Describe("Pod groups", func() {
})

ginkgo.By("Use events to observe the default-priority pods are getting preempted", func() {
preemptedPods := sets.New[types.NamespacedName]()
gomega.Eventually(func(g gomega.Gomega) sets.Set[types.NamespacedName] {
select {
case evt, ok := <-eventWatcher.ResultChan():
g.Expect(ok).To(gomega.BeTrue())
event, ok := evt.Object.(*corev1.Event)
g.Expect(ok).To(gomega.BeTrue())
if event.InvolvedObject.Namespace == ns.Name && event.Reason == "Stopped" {
objKey := types.NamespacedName{Namespace: event.InvolvedObject.Namespace, Name: event.InvolvedObject.Name}
preemptedPods.Insert(objKey)
}
default:
}
return preemptedPods
}, util.Timeout, util.Interval).Should(gomega.Equal(defaultGroupPods))
util.ExpectEventsForObjects(eventWatcher, defaultGroupPods, func(e *corev1.Event) bool {
return e.InvolvedObject.Namespace == ns.Name && e.Reason == "Stopped"
})
})

replacementPods := make(map[types.NamespacedName]types.NamespacedName, len(defaultPriorityGroup))
Expand Down
4 changes: 2 additions & 2 deletions test/util/constants.go
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
Timeout = time.Second * 30
Timeout = time.Second * 5
// LongTimeout is meant for E2E tests when waiting for complex operations
// such as running pods to completion.
LongTimeout = 45 * time.Second
Expand All @@ -31,6 +31,6 @@ const (
// need started and the time it takes for a change in ready probe response triggers
// a change in the deployment status.
StartUpTimeout = 5 * time.Minute
ConsistentDuration = time.Second * 3
ConsistentDuration = time.Second
Interval = time.Millisecond * 250
)
25 changes: 25 additions & 0 deletions test/util/util.go
Expand Up @@ -19,6 +19,7 @@ package util
import (
"context"
"fmt"
"time"

"github.com/google/go-cmp/cmp/cmpopts"
"github.com/onsi/ginkgo/v2"
Expand All @@ -30,6 +31,8 @@ import (
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/component-base/metrics/testutil"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -666,3 +669,25 @@ func ExpectPodsFinalized(ctx context.Context, k8sClient client.Client, keys ...t
}, Timeout, Interval).Should(gomega.BeEmpty(), "Expected pod to be finalized")
}
}

func ExpectEventsForObjects(eventWatcher watch.Interface, objs sets.Set[types.NamespacedName], filter func(*corev1.Event) bool) {
gotObjs := sets.New[types.NamespacedName]()
timeoutCh := time.After(Timeout)
readCh:
for !gotObjs.Equal(objs) {
select {

case evt, ok := <-eventWatcher.ResultChan():
gomega.Expect(ok).To(gomega.BeTrue())
event, ok := evt.Object.(*corev1.Event)
gomega.Expect(ok).To(gomega.BeTrue())
if filter(event) {
objKey := types.NamespacedName{Namespace: event.InvolvedObject.Namespace, Name: event.InvolvedObject.Name}
gotObjs.Insert(objKey)
}
case <-timeoutCh:
break readCh
}
}
gomega.ExpectWithOffset(1, gotObjs).To(gomega.Equal(objs))
}

0 comments on commit 69385f4

Please sign in to comment.