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

test: fix external git flake #3039

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions src/test/external/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package external

import (
"errors"
"path"
"path/filepath"
"strings"
Expand All @@ -31,17 +32,15 @@ func createPodInfoPackageWithInsecureSources(t *testing.T, temp string) {
exec.CmdWithPrint(zarfBinPath, "package", "create", temp, "--confirm", "--output", temp)
}

func verifyWaitSuccess(t *testing.T, timeoutMinutes time.Duration, cmd string, args []string, condition string, onTimeout string) bool {
func waitForCondition(t *testing.T, timeoutMinutes time.Duration, cmd string, args []string, condition string) error {
timeout := time.After(timeoutMinutes * time.Minute)
for {
// delay check 3 seconds
time.Sleep(3 * time.Second)
select {
// on timeout abort
case <-timeout:
t.Error(onTimeout)

return false
return errors.New("timed out waiting for condition")

// after delay, try running
default:
Expand All @@ -52,7 +51,7 @@ func verifyWaitSuccess(t *testing.T, timeoutMinutes time.Duration, cmd string, a
t.Log(string(stdOut), err)
}
if strings.Contains(string(stdOut), condition) {
return true
return nil
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/external/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ services:
ports:
- "3000:3000"
- "222:22"
healthcheck:
test: ["CMD", "curl", "-f", "http://gitea.localhost:3000/api/healthz"]
interval: 5s
timeout: 5s
retries: 20
init:
image: gitea/gitea:1.18.1
container_name: gitea.init
Expand Down
7 changes: 3 additions & 4 deletions src/test/external/ext_out_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ func (suite *ExtOutClusterTestSuite) SetupSuite() {
suite.NoError(err, "unable to install the gitea-server")

// Wait for gitea to deploy properly
giteaArgs := []string{"inspect", "-f", "{{.State.Status}}", "gitea.init"}
giteaErrStr := "unable to verify the gitea container installed successfully"
success := verifyWaitSuccess(suite.T(), 2, "docker", giteaArgs, "exited", giteaErrStr)
suite.True(success, giteaErrStr)
giteaArgs := []string{"inspect", "-f", "{{.State.Health.Status}}", "gitea.localhost"}
err = waitForCondition(suite.T(), 2, "docker", giteaArgs, "healthy")
suite.NoError(err)

// Connect gitea to the k3d network
err = exec.CmdWithPrint("docker", "network", "connect", "--ip", giteaIP, network, giteaHost)
Expand Down