Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust base timeouts for integration and E2E tests #1919

Merged
merged 1 commit into from Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation only processed one event every 250ms

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))
}