Skip to content

Commit 77beec1

Browse files
committed
testGatewayAPIObjects: Improve logging
Add more logging to functions that testGatewayAPIObjects uses in order to make it easier to diagnose test failures. * test/e2e/gateway_api_test.go (ensureGatewayObjectSuccess): Remove t.Helper() and add more logging. This function has core test logic that can mark the test as failed, and marking this function as a helper obfuscates the point of failure. * test/e2e/util_gatewayapi_test.go (assertGatewayClassSuccessful): Add more logging. (assertGatewaySuccessful): Add more logging. (assertHttpRouteSuccessful): Add more logging. (assertHttpRouteConnection): Remove t.Helper() and add more logging. (assertDNSRecord): Add more logging.
1 parent 86eede8 commit 77beec1

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

test/e2e/gateway_api_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,27 +366,27 @@ func ensureGatewayObjectCreation(ns *corev1.Namespace) error {
366366
// ensureGatewayObjectSuccess tests that gateway class, gateway, and http route objects were accepted as valid,
367367
// and that a curl to the application via the http route returns with a valid response.
368368
func ensureGatewayObjectSuccess(t *testing.T, ns *corev1.Namespace) []string {
369-
t.Helper()
370369
errs := []string{}
371370
gateway := &gatewayapiv1.Gateway{}
372371

373-
// Make sure gateway class was created successfully.
372+
t.Log("Making sure the gatewayclass is created and accepted...")
374373
_, err := assertGatewayClassSuccessful(t, operatorcontroller.OpenShiftDefaultGatewayClassName)
375374
if err != nil {
376375
errs = append(errs, error.Error(err))
377376
}
378377

379-
// Make sure gateway was created successfully.
378+
t.Log("Making sure the gateway is created and accepted...")
380379
gateway, err = assertGatewaySuccessful(t, operatorcontroller.DefaultOperandNamespace, testGatewayName)
381380
if err != nil {
382381
errs = append(errs, error.Error(err))
383382
}
384383

384+
t.Log("Making sure the httproute is created and accepted...")
385385
_, err = assertHttpRouteSuccessful(t, ns.Name, "test-httproute", gateway)
386386
if err != nil {
387387
errs = append(errs, error.Error(err))
388388
} else {
389-
// Validate the connectivity to the backend app via http route.
389+
t.Log("Validating the connectivity to the backend application via the httproute...")
390390
err = assertHttpRouteConnection(t, defaultRoutename, gateway)
391391
if err != nil {
392392
errs = append(errs, error.Error(err))

test/e2e/util_gatewayapi_test.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func assertGatewayClassSuccessful(t *testing.T, name string) (*gatewayapiv1.Gate
529529
// Wait up to 2 minutes for the gateway class to be Accepted.
530530
err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 2*time.Minute, false, func(context context.Context) (bool, error) {
531531
if err := kclient.Get(context, nsName, gwc); err != nil {
532-
t.Logf("failed to get gateway class %s, retrying...", name)
532+
t.Logf("Failed to get gatewayclass %s: %v", name, err)
533533
return false, nil
534534
}
535535
for _, condition := range gwc.Status.Conditions {
@@ -540,14 +540,15 @@ func assertGatewayClassSuccessful(t *testing.T, name string) (*gatewayapiv1.Gate
540540
}
541541
}
542542
}
543-
t.Logf("found gateway class %s, but it is not yet Accepted. Retrying...", name)
543+
t.Logf("Found gatewayclass %s, but it is not yet accepted. Retrying...", name)
544544
return false, nil
545545
})
546546
if err != nil {
547-
return nil, fmt.Errorf("gateway class %s not %v, last recorded status message: %s", name, gatewayapiv1.GatewayClassConditionStatusAccepted, recordedConditionMsg)
547+
return nil, fmt.Errorf("gatewayclass %s is not %v; last recorded status message: %s", name, gatewayapiv1.GatewayClassConditionStatusAccepted, recordedConditionMsg)
548548
}
549549

550-
t.Logf("gateway class %s successful", name)
550+
t.Logf("Observed that gatewayclass %s has been accepted: %+v", name, gwc.Status)
551+
551552
return gwc, nil
552553
}
553554

@@ -562,14 +563,14 @@ func assertGatewaySuccessful(t *testing.T, namespace, name string) (*gatewayapiv
562563

563564
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 1*time.Minute, false, func(context context.Context) (bool, error) {
564565
if err := kclient.Get(context, nsName, gw); err != nil {
565-
t.Logf("failed to get gateway %s, retrying...", name)
566+
t.Logf("Failed to get gateway %v: %v", nsName, err)
566567
return false, nil
567568
}
568569
for _, condition := range gw.Status.Conditions {
569570
if condition.Type == string(gatewayapiv1.GatewayConditionAccepted) {
570571
recordedConditionMsg = condition.Message
571572
if condition.Status == metav1.ConditionTrue {
572-
t.Logf("found gateway %s/%s as Accepted", namespace, name)
573+
t.Logf("Found gateway %v as Accepted", nsName)
573574
return true, nil
574575
}
575576
}
@@ -578,9 +579,11 @@ func assertGatewaySuccessful(t *testing.T, namespace, name string) (*gatewayapiv
578579
})
579580
if err != nil {
580581
t.Logf("Last observed gateway:\n%s", util.ToYaml(gw))
581-
return nil, fmt.Errorf("gateway %s not %v, last recorded status message: %s", name, gatewayapiv1.GatewayConditionAccepted, recordedConditionMsg)
582+
return nil, fmt.Errorf("Gateway %v not %v, last recorded status message: %s", nsName, gatewayapiv1.GatewayConditionAccepted, recordedConditionMsg)
582583
}
583584

585+
t.Logf("Observed that gateway %v has been accepted: %+v", nsName, gw.Status)
586+
584587
return gw, nil
585588
}
586589

@@ -598,15 +601,15 @@ func assertHttpRouteSuccessful(t *testing.T, namespace, name string, gateway *ga
598601
// Wait 1 minute for parent/s to update
599602
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 1*time.Minute, false, func(context context.Context) (bool, error) {
600603
if err := kclient.Get(context, nsName, httproute); err != nil {
601-
t.Logf("failed to get httproute %s/%s, retrying...", namespace, name)
604+
t.Logf("Failed to get httproute %v: %v", nsName, err)
602605
return false, nil
603606
}
604607
numParents := len(httproute.Status.Parents)
605608
if numParents == 0 {
606-
t.Logf("httpRoute %s/%s has no parent conditions, retrying...", namespace, name)
609+
t.Logf("Found no parents in httproute %v status: %+v", nsName, httproute.Status)
607610
return false, nil
608611
}
609-
t.Logf("found httproute %s/%s with %d parent/s", namespace, name, numParents)
612+
t.Logf("Found httproute %v with %d parent/s: %+v", nsName, numParents, httproute.Status)
610613
return true, nil
611614
})
612615
if err != nil {
@@ -646,14 +649,15 @@ func assertHttpRouteSuccessful(t *testing.T, namespace, name string, gateway *ga
646649
return nil, fmt.Errorf("httpRoute %s/%s, parent %v/%v not %v, last recorded status message: %s", namespace, name, parent.ParentRef.Namespace, parent.ParentRef.Name, gatewayapiv1.RouteConditionResolvedRefs, resolvedRefConditionMsg)
647650
}
648651
}
649-
t.Logf("httpRoute %s/%s successful", namespace, name)
652+
653+
t.Logf("Observed that all parents of httproute %v report accepted and resolved: %+v", nsName, httproute.Status)
654+
650655
return httproute, nil
651656
}
652657

653658
// assertHttpRouteConnection checks if the http route of the given name replies successfully,
654659
// and returns an error if not
655660
func assertHttpRouteConnection(t *testing.T, hostname string, gateway *gatewayapiv1.Gateway) error {
656-
t.Helper()
657661
domain := ""
658662

659663
// Create the http client to check the header.
@@ -676,13 +680,12 @@ func assertHttpRouteConnection(t *testing.T, hostname string, gateway *gatewayap
676680
// Obtain the standard formatting of the dnsRecord.
677681
dnsRecordName := operatorcontroller.GatewayDNSRecordName(gateway, domain)
678682

679-
// Make sure the DNSRecord is ready to use.
683+
t.Logf("Making sure the DNSRecord %v for domain %q is ready to use...", dnsRecordName, domain)
680684
if err := assertDNSRecord(t, dnsRecordName); err != nil {
681685
return err
682686
}
683687

684-
// Wait and check that the dns name resolves first. Takes a long time, so
685-
// if the hostname is actually an IP address, skip this.
688+
t.Logf("Attempting to resolve %s...", hostname)
686689
if net.ParseIP(hostname) == nil {
687690
if err := wait.PollUntilContextTimeout(context.Background(), 10*time.Second, dnsResolutionTimeout, false, func(context context.Context) (bool, error) {
688691
_, err := net.LookupHost(hostname)
@@ -701,7 +704,7 @@ func assertHttpRouteConnection(t *testing.T, hostname string, gateway *gatewayap
701704
body string
702705
headers http.Header
703706
)
704-
// Wait for http route to respond, and when it does, check for the status code.
707+
t.Logf("Probing %s...", hostname)
705708
if err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 5*time.Minute, false, func(context context.Context) (bool, error) {
706709
var err error
707710
statusCode, headers, body, err = getHTTPResponse(client, hostname)
@@ -713,15 +716,15 @@ func assertHttpRouteConnection(t *testing.T, hostname string, gateway *gatewayap
713716
t.Logf("GET %s failed: status %v, expected %v, retrying...", hostname, statusCode, http.StatusOK)
714717
return false, nil // retry on 503 as pod/service may not be ready
715718
}
716-
t.Logf("request to %s was successful", hostname)
719+
t.Logf("Request to %s was successful", hostname)
717720
return true, nil
718721

719722
}); err != nil {
720723
if statusCode != 0 {
721724
t.Log("Response headers for most recent request:", headers)
722725
t.Log("Reponse body for most recent request:", body)
723726
}
724-
t.Fatalf("error contacting %s's endpoint: %v", hostname, err)
727+
t.Fatalf("Error connecting to %s: %v", hostname, err)
725728
}
726729

727730
return nil
@@ -843,20 +846,21 @@ func assertDNSRecord(t *testing.T, recordName types.NamespacedName) error {
843846

844847
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 1*time.Minute, false, func(context context.Context) (bool, error) {
845848
if err := kclient.Get(context, recordName, dnsRecord); err != nil {
846-
t.Logf("failed to get DNSRecord %s/%s: %v, retrying...", recordName.Namespace, recordName.Name, err)
849+
t.Logf("Failed to get DNSRecord %v: %v", recordName, err)
847850
return false, nil
848851
}
849852
// Determine the current state of the DNSRecord.
850853
if len(dnsRecord.Status.Zones) > 0 {
851854
for _, zone := range dnsRecord.Status.Zones {
852855
for _, condition := range zone.Conditions {
853856
if condition.Type == v1.DNSRecordPublishedConditionType && condition.Status == string(metav1.ConditionTrue) {
857+
t.Logf("Found DNSRecord %v %s=%s", recordName, condition.Type, condition.Status)
854858
return true, nil
855859
}
856860
}
857861
}
858862
}
859-
t.Logf("found DNSRecord %s/%s but could not determine its readiness. Retrying...", recordName.Namespace, recordName.Name)
863+
t.Logf("Found DNSRecord %v but could not determine its readiness. Retrying...", recordName)
860864
return false, nil
861865
})
862866
return err

0 commit comments

Comments
 (0)