diff --git a/test/e2e_flags.go b/test/e2e_flags.go index 153e3e328123..a492ae3c6e79 100644 --- a/test/e2e_flags.go +++ b/test/e2e_flags.go @@ -33,6 +33,9 @@ type ServingEnvironmentFlags struct { ResolvableDomain bool // Resolve Route controller's `domainSuffix` Https bool // Indicates where the test service will be created with https IngressClass string // Indicates the class of Ingress provider to test. + // Indicates how many consecutive requests sent against the ingress should be + // successful before claiming the Ingress ready. + IngressRetries int CertificateClass string // Indicates the class of Certificate provider to test. SystemNamespace string // Indicates the system namespace, in which Knative Serving is installed. } @@ -48,6 +51,8 @@ func initializeServingFlags() *ServingEnvironmentFlags { flag.StringVar(&f.IngressClass, "ingressClass", network.IstioIngressClassName, "Set this flag to the ingress class to test against.") + flag.IntVar(&f.IngressRetries, "ingressRetries", 0, + "Set this flag to a positive number to enforce retrying ingress consistency in tests.") flag.StringVar(&f.CertificateClass, "certificateClass", network.CertManagerCertificateClassName, "Set this flag to the certificate class to test against.") diff --git a/test/v1/route.go b/test/v1/route.go index 740a49ab1d41..6b86ac291a6e 100644 --- a/test/v1/route.go +++ b/test/v1/route.go @@ -114,10 +114,22 @@ func IsRouteNotReady(r *v1.Route) (bool, error) { return !r.Status.IsReady(), nil } -// RetryingRouteInconsistency retries common requests seen when creating a new route +// RetryingRouteInconsistency conditionally retries common requests seen when creating a new route. func RetryingRouteInconsistency(innerCheck spoof.ResponseChecker) spoof.ResponseChecker { + if test.ServingFlags.IngressRetries > 0 { + var successes int + return func(resp *spoof.Response) (bool, error) { + success, err := innerCheck(resp) + if !success { + successes = 0 + return false, err + } + successes++ + return successes == test.ServingFlags.IngressRetries, err + } + } + // By default only wrap the innerCheck. return func(resp *spoof.Response) (bool, error) { - // If we didn't match any retryable codes, invoke the ResponseChecker that we wrapped. return innerCheck(resp) } } diff --git a/test/v1alpha1/route.go b/test/v1alpha1/route.go index 4ff55e2ac515..99326ab2edc1 100644 --- a/test/v1alpha1/route.go +++ b/test/v1alpha1/route.go @@ -50,11 +50,22 @@ func CreateRoute(t pkgTest.T, clients *test.Clients, names test.ResourceNames, f return clients.ServingAlphaClient.Routes.Create(route) } -// RetryingRouteInconsistency retries common requests seen when creating a new route -// TODO(5573): Remove this. +// RetryingRouteInconsistency conditionally retries common requests seen when creating a new route. func RetryingRouteInconsistency(innerCheck spoof.ResponseChecker) spoof.ResponseChecker { + if test.ServingFlags.IngressRetries > 0 { + var successes int + return func(resp *spoof.Response) (bool, error) { + success, err := innerCheck(resp) + if !success { + successes = 0 + return false, err + } + successes++ + return successes == test.ServingFlags.IngressRetries, err + } + } + // By default only wrap the innerCheck. return func(resp *spoof.Response) (bool, error) { - // If we didn't match any retryable codes, invoke the ResponseChecker that we wrapped. return innerCheck(resp) } } diff --git a/test/v1beta1/route.go b/test/v1beta1/route.go index 4ee7dc21318a..fcd980c7b184 100644 --- a/test/v1beta1/route.go +++ b/test/v1beta1/route.go @@ -116,10 +116,22 @@ func IsRouteFailed(r *v1beta1.Route) (bool, error) { return r.IsFailed(), nil } -// RetryingRouteInconsistency retries common requests seen when creating a new route +// RetryingRouteInconsistency conditionally retries common requests seen when creating a new route. func RetryingRouteInconsistency(innerCheck spoof.ResponseChecker) spoof.ResponseChecker { + if test.ServingFlags.IngressRetries > 0 { + var successes int + return func(resp *spoof.Response) (bool, error) { + success, err := innerCheck(resp) + if !success { + successes = 0 + return false, err + } + successes++ + return successes == test.ServingFlags.IngressRetries, err + } + } + // By default only wrap the innerCheck. return func(resp *spoof.Response) (bool, error) { - // If we didn't match any retryable codes, invoke the ResponseChecker that we wrapped. return innerCheck(resp) } }