Skip to content

Commit

Permalink
test: fix external git flake (#3039)
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Abro <[email protected]>
  • Loading branch information
AustinAbro321 authored Sep 26, 2024
1 parent 2c8b671 commit fce521d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
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

0 comments on commit fce521d

Please sign in to comment.