e2e framework: configure poll interval+duration for gomega

Primarily this protects against accidentally polling with the default interval
of 10ms. Setting these defaults may also make some tests simpler because they
don't need to override the defaults.
This commit is contained in:
Patrick Ohly 2023-01-03 20:03:20 +01:00
parent 16a6f70e11
commit 0f9a8d38be
2 changed files with 14 additions and 0 deletions

View File

@ -32,6 +32,7 @@ import (
"github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/types" "github.com/onsi/ginkgo/v2/types"
"github.com/onsi/gomega"
gomegaformat "github.com/onsi/gomega/format" gomegaformat "github.com/onsi/gomega/format"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
@ -472,6 +473,15 @@ func AfterReadingAllFlags(t *TestContextType) {
os.Exit(0) os.Exit(0)
} }
// Reconfigure gomega defaults. The poll interval should be suitable
// for most tests. The timeouts are more subjective and tests may want
// to override them, but these defaults are still better for E2E than the
// ones from Gomega (1s timeout, 10ms interval).
gomega.SetDefaultEventuallyPollingInterval(t.timeouts.Poll)
gomega.SetDefaultConsistentlyPollingInterval(t.timeouts.Poll)
gomega.SetDefaultEventuallyTimeout(t.timeouts.PodStart)
gomega.SetDefaultConsistentlyDuration(t.timeouts.PodStartShort)
// Only set a default host if one won't be supplied via kubeconfig // Only set a default host if one won't be supplied via kubeconfig
if len(t.Host) == 0 && len(t.KubeConfig) == 0 { if len(t.Host) == 0 && len(t.KubeConfig) == 0 {
// Check if we can use the in-cluster config // Check if we can use the in-cluster config

View File

@ -47,10 +47,12 @@ type TimeoutContext struct {
Poll time.Duration Poll time.Duration
// PodStart is how long to wait for the pod to be started. // PodStart is how long to wait for the pod to be started.
// This value is the default for gomega.Eventually.
PodStart time.Duration PodStart time.Duration
// PodStartShort is same as `PodStart`, but shorter. // PodStartShort is same as `PodStart`, but shorter.
// Use it in a case-by-case basis, mostly when you are sure pod start will not be delayed. // Use it in a case-by-case basis, mostly when you are sure pod start will not be delayed.
// This value is the default for gomega.Consistently.
PodStartShort time.Duration PodStartShort time.Duration
// PodStartSlow is same as `PodStart`, but longer. // PodStartSlow is same as `PodStart`, but longer.
@ -118,6 +120,8 @@ func NewTimeoutContext() *TimeoutContext {
// PollInterval defines how long to wait between API server queries while // PollInterval defines how long to wait between API server queries while
// waiting for some condition. // waiting for some condition.
//
// This value is the default for gomega.Eventually and gomega.Consistently.
func PollInterval() time.Duration { func PollInterval() time.Duration {
return TestContext.timeouts.Poll return TestContext.timeouts.Poll
} }