Skip to content

Commit

Permalink
Wait for Route readiness in TestSingleConcurrency (#2308)
Browse files Browse the repository at this point in the history
* Wait for Route readiness in TestSingleConcurrency

TestSingleConcurrency was waiting for the Revision to be Ready but
should also wait on the Route to both be Ready and respond
successfully to a request before proceeding with the rest of the test.

* golint
  • Loading branch information
bbrowning authored and knative-prow-robot committed Oct 25, 2018
1 parent 62fc8ee commit c8d2b27
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
18 changes: 1 addition & 17 deletions test/conformance/blue_green_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ const (
expectedGreen = "Re-energize yourself with a slice of pepperoni!"
)

// Probe until we get a successful response. This ensures the domain is
// routable before we send it a bunch of traffic.
func probeDomain(logger *logging.BaseLogger, clients *test.Clients, domain string) error {
client, err := pkgTest.NewSpoofingClient(clients.KubeClient, logger, domain, test.ServingFlags.ResolvableDomain)
if err != nil {
return err
}
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s", domain), nil)
if err != nil {
return err
}
// TODO(tcnghia): Replace this probing with Status check when we have them.
_, err = client.Poll(req, pkgTest.Retrying(pkgTest.MatchesAny, http.StatusNotFound, http.StatusServiceUnavailable))
return err
}

// sendRequests sends "num" requests to "domain", returning a string for each spoof.Response.Body.
func sendRequests(client spoof.Interface, domain string, num int) ([]string, error) {
responses := make([]string, num)
Expand Down Expand Up @@ -254,7 +238,7 @@ func TestBlueGreenRoute(t *testing.T) {
// does not expose a Status, so we rely on probes to know when they are effective.
// It doesn't matter which domain we probe, we just need to choose one.
logger.Infof("Probing domain %s", tealDomain)
if err := probeDomain(logger, clients, tealDomain); err != nil {
if err := test.ProbeDomain(logger, clients, tealDomain); err != nil {
t.Fatalf("Error probing domain %s: %v", tealDomain, err)
}

Expand Down
12 changes: 12 additions & 0 deletions test/conformance/single_threaded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,24 @@ func TestSingleConcurrency(t *testing.T) {
t.Fatalf("The Revision %q still can't serve traffic: %v", names.Revision, err)
}

logger.Info("When the Route reports as Ready, everything should be ready.")
if err := test.WaitForRouteState(clients.ServingClient, names.Route, test.IsRouteReady, "RouteIsReady"); err != nil {
t.Fatalf("The Route %s was not marked as Ready to serve traffic: %v", names.Route, err)
}

route, err := clients.ServingClient.Routes.Get(names.Route, metav1.GetOptions{})
if err != nil {
t.Fatalf("Error fetching Route %s: %v", names.Route, err)
}
domain := route.Status.Domain

// Ready does not actually mean Ready for a Route just yet.
// See https://github.com/knative/serving/issues/1582
logger.Infof("Probing domain %s", domain)
if err := test.ProbeDomain(logger, clients, domain); err != nil {
t.Fatalf("Error probing domain %s: %v", domain, err)
}

client, err := pkgTest.NewSpoofingClient(clients.KubeClient, logger, domain, test.ServingFlags.ResolvableDomain)
if err != nil {
t.Fatalf("Error creating spoofing client: %v", err)
Expand Down
17 changes: 17 additions & 0 deletions test/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ func CreateBlueGreenRoute(logger *logging.BaseLogger, clients *Clients, names, b
return err
}

// ProbeDomain sends requests to a domain until we get a successful
// response. This ensures the domain is routable before we send it a
// bunch of traffic.
func ProbeDomain(logger *logging.BaseLogger, clients *Clients, domain string) error {
client, err := pkgTest.NewSpoofingClient(clients.KubeClient, logger, domain, ServingFlags.ResolvableDomain)
if err != nil {
return err
}
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s", domain), nil)
if err != nil {
return err
}
// TODO(tcnghia): Replace this probing with Status check when we have them.
_, err = client.Poll(req, pkgTest.Retrying(pkgTest.MatchesAny, http.StatusNotFound, http.StatusServiceUnavailable))
return err
}

// RunRouteProber creates and runs a prober as background goroutine to keep polling Route.
// It stops when getting an error response from Route.
func RunRouteProber(logger *logging.BaseLogger, clients *Clients, domain string) <-chan error {
Expand Down

0 comments on commit c8d2b27

Please sign in to comment.