Skip to content

Commit

Permalink
Add retries to NGF Pod log assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
bjee19 committed Sep 3, 2024
1 parent 4467880 commit 7cd5a5c
Showing 1 changed file with 50 additions and 22 deletions.
72 changes: 50 additions & 22 deletions tests/suite/nginxgateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"strings"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -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())
})
})

Expand All @@ -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())
})
})
})
Expand Down Expand Up @@ -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())
})
})

Expand All @@ -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())
})
})
})
Expand Down

0 comments on commit 7cd5a5c

Please sign in to comment.