From 7cd5a5c14cc2750cdd0a113f0a74da0da5f8ec24 Mon Sep 17 00:00:00 2001 From: Benjamin Jee Date: Tue, 3 Sep 2024 14:20:00 -0700 Subject: [PATCH] Add retries to NGF Pod log assertions --- tests/suite/nginxgateway_test.go | 72 ++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/tests/suite/nginxgateway_test.go b/tests/suite/nginxgateway_test.go index 4de48f7874..3311ab3a12 100644 --- a/tests/suite/nginxgateway_test.go +++ b/tests/suite/nginxgateway_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strings" "time" . "github.com/onsi/ginkgo/v2" @@ -104,12 +105,19 @@ var _ = Describe("NginxGateway", Ordered, Label("functional", "nginxGateway"), f _, err = verifyAndReturnNginxGateway(nginxGatewayNsname) Expect(err).ToNot(HaveOccurred()) - logs, err := resourceManager.GetPodLogs(ngfNamespace, ngfPodName, &core.PodLogOptions{ - Container: "nginx-gateway", - }) - Expect(err).ToNot(HaveOccurred()) + Eventually( + func() bool { + logs, err := resourceManager.GetPodLogs(ngfNamespace, ngfPodName, &core.PodLogOptions{ + Container: "nginx-gateway", + }) + if err != nil { + return false + } - Expect(logs).To(ContainSubstring("\"level\":\"debug\"")) + return strings.Contains(logs, "\"level\":\"debug\"") + }).WithTimeout(timeoutConfig.GetTimeout). + WithPolling(500 * time.Millisecond). + Should(BeTrue()) }) }) @@ -129,12 +137,19 @@ var _ = Describe("NginxGateway", Ordered, Label("functional", "nginxGateway"), f Expect(nginxGateway.Status.Conditions[0].ObservedGeneration).To(Equal(int64(1))) - logs, err := resourceManager.GetPodLogs(ngfNamespace, ngfPodName, &core.PodLogOptions{ - Container: "nginx-gateway", - }) - Expect(err).ToNot(HaveOccurred()) + Eventually( + func() bool { + logs, err := resourceManager.GetPodLogs(ngfNamespace, ngfPodName, &core.PodLogOptions{ + Container: "nginx-gateway", + }) + if err != nil { + return false + } - Expect(logs).ToNot(ContainSubstring("\"level\":\"debug\"")) + return !strings.Contains(logs, "\"level\":\"debug\"") + }).WithTimeout(timeoutConfig.GetTimeout). + WithPolling(500 * time.Millisecond). + Should(BeTrue()) }) }) }) @@ -179,14 +194,20 @@ var _ = Describe("NginxGateway", Ordered, Label("functional", "nginxGateway"), f WithPolling(500 * time.Millisecond). Should(BeTrue()) - logs, err = resourceManager.GetPodLogs(ngfNamespace, ngfPodName, &core.PodLogOptions{ - Container: "nginx-gateway", - }) - Expect(err).ToNot(HaveOccurred()) + Eventually( + func() bool { + logs, err := resourceManager.GetPodLogs(ngfNamespace, ngfPodName, &core.PodLogOptions{ + Container: "nginx-gateway", + }) + if err != nil { + return false + } - Expect(logs).To(ContainSubstring( - "\"current\":\"debug\",\"msg\":\"Log level changed\",\"prev\":\"info\"", - )) + return strings.Contains(logs, + "\"current\":\"debug\",\"msg\":\"Log level changed\",\"prev\":\"info\"") + }).WithTimeout(timeoutConfig.GetTimeout). + WithPolling(500 * time.Millisecond). + Should(BeTrue()) }) }) @@ -202,12 +223,19 @@ var _ = Describe("NginxGateway", Ordered, Label("functional", "nginxGateway"), f WithPolling(500 * time.Millisecond). Should(MatchError("failed to get nginxGateway")) - logs, err := resourceManager.GetPodLogs(ngfNamespace, ngfPodName, &core.PodLogOptions{ - Container: "nginx-gateway", - }) - Expect(err).ToNot(HaveOccurred()) + Eventually( + func() bool { + logs, err := resourceManager.GetPodLogs(ngfNamespace, ngfPodName, &core.PodLogOptions{ + Container: "nginx-gateway", + }) + if err != nil { + return false + } - Expect(logs).To(ContainSubstring("NginxGateway configuration was deleted; using defaults")) + return strings.Contains(logs, "NginxGateway configuration was deleted; using defaults") + }).WithTimeout(timeoutConfig.GetTimeout). + WithPolling(500 * time.Millisecond). + Should(BeTrue()) }) }) })