Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Retry image pull for 3 times and then fail #137

Merged
merged 1 commit into from
Mar 27, 2024
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
16 changes: 15 additions & 1 deletion tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"

"github.com/runfinch/common-tests/fnet"

Expand Down Expand Up @@ -78,6 +79,8 @@ const (
Hybrid
// Unified with only cgroups v2 mounted.
Unified

retryPull = 3
)

// SetupLocalRegistry can be invoked before running the tests to save time when pulling images during tests.
Expand All @@ -102,7 +105,18 @@ 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)
command.New(o, "pull", ref).WithTimeoutInSeconds(60).Run()
// retry pull for 3 times
var session *gexec.Session
for i := 0; i < retryPull; i++ {
session = command.New(o, "pull", ref).WithTimeoutInSeconds(30).WithoutSuccessfulExit().Run()
if session.ExitCode() == 0 {
break
}
}
if session.ExitCode() != 0 {
ginkgo.Fail("Failed to pull image " + ref)
}

localRef := fmt.Sprintf("localhost:%d/%s", hostPort, name)
command.Run(o, "tag", ref, localRef)
command.Run(o, "push", localRef)
Expand Down
Loading