From 3b693190773706dde9b6f8dd11171e26cc0df404 Mon Sep 17 00:00:00 2001 From: Subhransu <47723536+Shubhranshu153@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:37:15 -0700 Subject: [PATCH] fix: add custom wait for retry logic (#141) Issue #, if available: *Description of changes:* Add a custom wait logic as the wait for goexec has an assertion, that marks the test fail in case of timeout. eventually is usually also used with an assertion. Without the wait logic the retry wont work due to assertion *Testing done:* - [ ] I've reviewed the guidance in CONTRIBUTING.md #### License Acceptance By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. Signed-off-by: Shubharanshu Mahapatra --- tests/tests.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/tests.go b/tests/tests.go index 65a5d17..c9d02ab 100644 --- a/tests/tests.go +++ b/tests/tests.go @@ -14,6 +14,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" @@ -105,15 +106,23 @@ func SetupLocalRegistry(o *option.Option) { _, name, _ := strings.Cut(ref, "/") // allow up to a minute for remote pulls to account for external network // latency/throughput issues or throttling (default is 10 seconds) - // retry pull for 3 times + // retry pull for 3 times. var session *gexec.Session + exitCode := -1 for i := 0; i < retryPull; i++ { - session = command.New(o, "pull", ref).WithTimeoutInSeconds(30).WithoutCheckingExitCode().Run() - if session.ExitCode() == 0 { + session = command.New(o, "pull", ref).WithoutWait().Run() + select { + case <-session.Exited: + exitCode = session.ExitCode() + case <-time.After(30 * time.Second): + fmt.Printf("Timeout occurred, command hasn't exited yet (attempt %d)", i) + session.Kill() + } + if exitCode == 0 { break } } - if session.ExitCode() != 0 { + if exitCode != 0 { ginkgo.Fail("Failed to pull image " + ref) }