Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
🔥 Apply carried patches.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanfx committed Jul 16, 2020
1 parent 6774c4a commit 8128e78
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
5 changes: 3 additions & 2 deletions test/e2e/grpc_test.go
Expand Up @@ -322,6 +322,7 @@ func streamTest(t *testing.T, resources *v1test.ResourceObjects, clients *test.C
func testGRPC(t *testing.T, f grpcTest, fopts ...rtesting.ServiceOption) {
t.Helper()
t.Parallel()
resolvable := false
cancel := logstream.Start(t)
defer cancel()

Expand Down Expand Up @@ -350,14 +351,14 @@ func testGRPC(t *testing.T, f grpcTest, fopts ...rtesting.ServiceOption) {
url,
v1test.RetryingRouteInconsistency(pkgTest.IsStatusOK),
"gRPCPingReadyToServe",
test.ServingFlags.ResolvableDomain,
resolvable,
test.AddRootCAtoTransport(t.Logf, clients, test.ServingFlags.Https),
); err != nil {
t.Fatalf("The endpoint for Route %s at %s didn't return success: %v", names.Route, url, err)
}

host := url.Host
if !test.ServingFlags.ResolvableDomain {
if !resolvable {
host = pkgTest.Flags.IngressEndpoint
if pkgTest.Flags.IngressEndpoint == "" {
host, err = ingress.GetIngressEndpoint(clients.KubeClient.Kube)
Expand Down
13 changes: 13 additions & 0 deletions test/v1/route.go
Expand Up @@ -19,6 +19,7 @@ package v1
import (
"context"
"fmt"
"net/http"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -115,8 +116,20 @@ func IsRouteFailed(r *v1.Route) (bool, error) {
}

// RetryingRouteInconsistency retries common requests seen when creating a new route
// - 404 until the route is propagated to the proxy
// - 503 to account for Openshift route inconsistency (https://jira.coreos.com/browse/SRVKS-157)
func RetryingRouteInconsistency(innerCheck spoof.ResponseChecker) spoof.ResponseChecker {
const neededSuccesses = 5
var successes int
return func(resp *spoof.Response) (bool, error) {
if resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusServiceUnavailable {
successes = 0
return false, nil
}
successes++
if successes < neededSuccesses {
return false, nil
}
// If we didn't match any retryable codes, invoke the ResponseChecker that we wrapped.
return innerCheck(resp)
}
Expand Down
14 changes: 13 additions & 1 deletion test/v1alpha1/route.go
Expand Up @@ -21,6 +21,7 @@ package v1alpha1
import (
"context"
"fmt"
"net/http"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -51,9 +52,20 @@ func CreateRoute(t pkgTest.T, clients *test.Clients, names test.ResourceNames, f
}

// RetryingRouteInconsistency retries common requests seen when creating a new route
// TODO(5573): Remove this.
// - 404 until the route is propagated to the proxy
// - 503 to account for Openshift route inconsistency (https://jira.coreos.com/browse/SRVKS-157)
func RetryingRouteInconsistency(innerCheck spoof.ResponseChecker) spoof.ResponseChecker {
const neededSuccesses = 5
var successes int
return func(resp *spoof.Response) (bool, error) {
if resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusServiceUnavailable {
successes = 0
return false, nil
}
successes++
if successes < neededSuccesses {
return false, nil
}
// If we didn't match any retryable codes, invoke the ResponseChecker that we wrapped.
return innerCheck(resp)
}
Expand Down
13 changes: 13 additions & 0 deletions test/v1beta1/route.go
Expand Up @@ -19,6 +19,7 @@ package v1beta1
import (
"context"
"fmt"
"net/http"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -117,8 +118,20 @@ func IsRouteFailed(r *v1beta1.Route) (bool, error) {
}

// RetryingRouteInconsistency retries common requests seen when creating a new route
// - 404 until the route is propagated to the proxy
// - 503 to account for Openshift route inconsistency (https://jira.coreos.com/browse/SRVKS-157)
func RetryingRouteInconsistency(innerCheck spoof.ResponseChecker) spoof.ResponseChecker {
const neededSuccesses = 5
var successes int
return func(resp *spoof.Response) (bool, error) {
if resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusServiceUnavailable {
successes = 0
return false, nil
}
successes++
if successes < neededSuccesses {
return false, nil
}
// If we didn't match any retryable codes, invoke the ResponseChecker that we wrapped.
return innerCheck(resp)
}
Expand Down
6 changes: 5 additions & 1 deletion vendor/knative.dev/pkg/test/helpers/name.go
Expand Up @@ -48,7 +48,11 @@ func ObjectPrefixForTest(t test.T) string {

// ObjectNameForTest generates a random object name based on the test name.
func ObjectNameForTest(t test.T) string {
return kmeta.ChildName(ObjectPrefixForTest(t), string(sep)+RandomString())
prefix := ObjectPrefixForTest(t)
if len(prefix) > 20 {
prefix = prefix[:20]
}
return kmeta.ChildName(prefix, string(sep)+RandomString())
}

// AppendRandomString will generate a random string that begins with prefix.
Expand Down

0 comments on commit 8128e78

Please sign in to comment.