Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion test/conformance/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package conformance

import (
"fmt"
"net/http"
"strings"
"testing"

Expand Down Expand Up @@ -83,7 +84,12 @@ func assertResourcesUpdatedWhenRevisionIsReady(t *testing.T, logger *zap.Sugared
t.Fatalf("Error fetching Route %s: %v", names.Route, err)
}

err = test.WaitForEndpointState(clients.Kube, logger, test.Flags.ResolvableDomain, updatedRoute.Status.Domain, test.EventuallyMatchesBody(expectedText), "WaitForEndpointToServeText")
expectedEndpointState := test.NewExpectedEndpointstate(updatedRoute.Status.Domain)
// TODO(#348): The ingress endpoint occasionally returns 503's and 404's.
// Explicitly allow 404's and 503's for a newly created revision.
expectedEndpointState.AllowableStatusCodes = []int{http.StatusServiceUnavailable, http.StatusNotFound}

err = test.WaitForEndpointState(clients.Kube, logger, test.Flags.ResolvableDomain, expectedEndpointState, test.EventuallyMatchesBody(expectedText), "WaitForEndpointToServeText")
if err != nil {
t.Fatalf("The endpoint for Route %s at domain %s didn't serve the expected text \"%s\": %v", names.Route, updatedRoute.Status.Domain, expectedText, err)
}
Expand Down
3 changes: 2 additions & 1 deletion test/conformance/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ func updateServiceWithImage(clients *test.Clients, names test.ResourceNames, ima

// Shamelessly cribbed from route_test. We expect the Route and Configuration to be ready if the Service is ready.
func assertServiceResourcesUpdated(t *testing.T, logger *zap.SugaredLogger, clients *test.Clients, names test.ResourceNames, routeDomain, expectedText string) {
expectedEndpointState := test.NewExpectedEndpointstate(routeDomain)
// TODO(#1178): Remove "Wait" from all checks below this point.
err := test.WaitForEndpointState(clients.Kube, logger, test.Flags.ResolvableDomain, routeDomain, test.EventuallyMatchesBody(expectedText), "WaitForEndpointToServeText")
err := test.WaitForEndpointState(clients.Kube, logger, test.Flags.ResolvableDomain, expectedEndpointState, test.EventuallyMatchesBody(expectedText), "WaitForEndpointToServeText")
if err != nil {
t.Fatalf("The endpoint for Route %s at domain %s didn't serve the expected text \"%s\": %v", names.Route, routeDomain, expectedText, err)
}
Expand Down
11 changes: 9 additions & 2 deletions test/e2e/autoscale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package e2e

import (
"net/http"
"strings"
"testing"

Expand Down Expand Up @@ -50,14 +51,15 @@ func isDeploymentScaledToZero() func(d *v1beta1.Deployment) (bool, error) {

func generateTrafficBurst(clients *test.Clients, logger *zap.SugaredLogger, num int, domain string) {
concurrentRequests := make(chan bool, num)
expectedEndpointState := test.NewExpectedEndpointstate(domain)

logger.Infof("Performing %d concurrent requests.", num)
for i := 0; i < num; i++ {
go func() {
test.WaitForEndpointState(clients.Kube,
logger,
test.Flags.ResolvableDomain,
domain,
expectedEndpointState,
test.EventuallyMatchesBody(autoscaleExpectedOutput),
"MakingConcurrentRequests")
concurrentRequests <- true
Expand Down Expand Up @@ -154,11 +156,16 @@ func TestAutoscaleUpDownUp(t *testing.T) {
}
domain := route.Status.Domain

expectedEndpointState := test.NewExpectedEndpointstate(domain)
// TODO(#348): The ingress endpoint occasionally returns 503's and 404's.
// Explicitly allow 404's and 503's for a newly created revision.
expectedEndpointState.AllowableStatusCodes = []int{http.StatusServiceUnavailable, http.StatusNotFound}

err = test.WaitForEndpointState(
clients.Kube,
logger,
test.Flags.ResolvableDomain,
domain,
expectedEndpointState,
test.EventuallyMatchesBody(autoscaleExpectedOutput),
"CheckingEndpointAfterUpdating")
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/helloworld_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ func TestHelloWorld(t *testing.T) {
}
domain := route.Status.Domain

err = test.WaitForEndpointState(clients.Kube, logger, test.Flags.ResolvableDomain, domain, test.MatchesBody(helloWorldExpectedOutput), "HelloWorldServesText")
expectedEndpointState := test.NewExpectedEndpointstate(domain)
err = test.WaitForEndpointState(clients.Kube, logger, test.Flags.ResolvableDomain, expectedEndpointState, test.MatchesBody(helloWorldExpectedOutput), "HelloWorldServesText")
if err != nil {
t.Fatalf("The endpoint for Route %s at domain %s didn't serve the expected text \"%s\": %v", names.Route, domain, helloWorldExpectedOutput, err)
}
Expand Down
24 changes: 19 additions & 5 deletions test/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ import (
"k8s.io/client-go/kubernetes"
)

type ExpectedEndpointState struct {
Domain string
AllowableStatusCodes []int
}

func NewExpectedEndpointstate(domain string) *ExpectedEndpointState {
return &ExpectedEndpointState{
Domain: domain,
// TODO(#348): The ingress endpoint tends to return 503's and 404's.
// Since there is currently a workaround for 503's, only allow 404's
// as an acceptable status code.
AllowableStatusCodes: []int{http.StatusNotFound},
}
}

// MatchesAny is a NOP matcher. This is useful for polling until a 200 is returned.
func MatchesAny(_ *spoof.Response) (bool, error) {
return true, nil
Expand Down Expand Up @@ -64,20 +79,19 @@ func EventuallyMatchesBody(expected string) spoof.ResponseChecker {
// the domain in the request headers, otherwise it will make the request directly to domain.
// desc will be used to name the metric that is emitted to track how long it took for the
// domain to get into the state checked by inState. Commas in `desc` must be escaped.
func WaitForEndpointState(kubeClientset *kubernetes.Clientset, logger *zap.SugaredLogger, resolvableDomain bool, domain string, inState spoof.ResponseChecker, desc string) error {
func WaitForEndpointState(kubeClientset *kubernetes.Clientset, logger *zap.SugaredLogger, resolvableDomain bool, expectedEndpointState *ExpectedEndpointState, inState spoof.ResponseChecker, desc string) error {
metricName := fmt.Sprintf("WaitForEndpointState/%s", desc)
_, span := trace.StartSpan(context.Background(), metricName)
defer span.End()

client, err := spoof.New(kubeClientset, logger, domain, resolvableDomain)
client, err := spoof.New(kubeClientset, logger, expectedEndpointState.Domain, resolvableDomain)
if err != nil {
return err
}

// TODO(#348): The ingress endpoint tends to return 503's and 404's
client.RetryCodes = []int{http.StatusServiceUnavailable, http.StatusNotFound}
client.RetryCodes = expectedEndpointState.AllowableStatusCodes

req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s", domain), nil)
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s", expectedEndpointState.Domain), nil)
if err != nil {
return err
}
Expand Down