Skip to content
Merged
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
12 changes: 9 additions & 3 deletions test/e2e/vpc-egress-gateway/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,15 @@ func checkEgressAccess(f *framework.Framework, namespaceName, svrPodName, image,
ginkgo.By("Checking connection from " + pod.Name + " to " + svrIP + " via " + protocol)
cmd := fmt.Sprintf("curl -q -s --connect-timeout 2 --max-time 2 %s/clientip", net.JoinHostPort(svrIP, svrPort))
ginkgo.By(fmt.Sprintf(`Executing %q in pod %s/%s`, cmd, pod.Namespace, pod.Name))
output := e2epodoutput.RunHostCmdOrDie(pod.Namespace, pod.Name, cmd)
clientIP, _, err := net.SplitHostPort(strings.TrimSpace(output))
framework.ExpectNoError(err)
var clientIP string
framework.WaitUntil(2*time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This retry logic is a good improvement for the flaky test. I have two suggestions for further improvement:

  1. WaitUntil function signature: The framework.WaitUntil function is a bit misleading. It accepts an interval as its first argument, but this argument is ignored, and a hardcoded 2-second interval is used instead. Your call works because you've passed 2*time.Second, matching the hardcoded value. This is worth noting as it has caused issues elsewhere (e.g., CheckPodEgressRoutes passes a 3-second interval that is ignored). A follow-up to refactor WaitUntil to use the interval parameter would improve the framework's clarity.

  2. Debugging: To make this test easier to debug if it times out, consider adding logging within the retry loop to show why a retry is happening. For example:

    func(_ context.Context) (bool, error) {
        output, err := e2epodoutput.RunHostCmd(pod.Namespace, pod.Name, cmd)
        if err != nil {
            framework.Logf("curl command failed, will retry: %v", err)
            return false, nil
        }
        clientIP, _, err = net.SplitHostPort(strings.TrimSpace(output))
        if err != nil {
            framework.Logf("failed to parse curl output, will retry. output: %q, error: %v", output, err)
        }
        return err == nil, nil
    }

output, err := e2epodoutput.RunHostCmd(pod.Namespace, pod.Name, cmd)
if err != nil {
return false, nil
}
clientIP, _, err = net.SplitHostPort(strings.TrimSpace(output))
return err == nil, nil
}, fmt.Sprintf("curl %s from pod %s/%s", net.JoinHostPort(svrIP, svrPort), pod.Namespace, pod.Name))
framework.ExpectContainElement(expectedClientIPs, clientIP)
}
}
Expand Down
Loading