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
27 changes: 22 additions & 5 deletions tests/e2e/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import (
"os"
"strings"
"testing"
"time"
)

const (
testNerdctl = "TestNerdctl"
testCtr = "TestCtr"
testCrictl = "TestCrictl"
testDocker = "TestDocker"
testNerdctl = "TestNerdctl"
testCtr = "TestCtr"
testCrictl = "TestCrictl"
testDocker = "TestDocker"
maxPullRetries = 5
pullRetryDelay = 2 * time.Second
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -114,7 +117,7 @@ func getTestImages(cases []containerTestArgs) []string {
func pullAllImages(testFunc string, images []string) error {
for _, image := range images {
log.Printf("Pulling image: %s", image)
if err := pullImageForTest(testFunc, image); err != nil {
if err := pullImageWithRetry(testFunc, image); err != nil {
return fmt.Errorf("failed to pull %s: %w", image, err)
}
}
Expand All @@ -130,6 +133,20 @@ func removeAllImages(testFunc string, images []string) {
}
}

func pullImageWithRetry(testFunc string, image string) error {
var err error
for i := 0; i < maxPullRetries; i++ {
err = pullImageForTest(testFunc, image)
if err == nil {
return nil
}

fmt.Printf("Attempt %d/%d failed to pull %s: %v. Retrying in %v...\n", i+1, maxPullRetries, image, err, pullRetryDelay)
time.Sleep(pullRetryDelay)
}
return fmt.Errorf("failed to pull %s after %d attempts: %w", image, maxPullRetries, err)
}

func pullImageForTest(testFunc string, image string) error {
switch testFunc {
case testCrictl:
Expand Down
Loading