Skip to content

Commit

Permalink
chore: Fix flaky cluster test (#15433)
Browse files Browse the repository at this point in the history
  • Loading branch information
jannfis authored Sep 9, 2023
1 parent 5a2097d commit 3d01b6d
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions test/e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/url"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -13,6 +14,7 @@ import (
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture"
accountFixture "github.com/argoproj/argo-cd/v2/test/e2e/fixture/account"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/app"
clusterFixture "github.com/argoproj/argo-cd/v2/test/e2e/fixture/cluster"
. "github.com/argoproj/argo-cd/v2/util/errors"
)
Expand All @@ -21,16 +23,38 @@ func TestClusterList(t *testing.T) {
SkipIfAlreadyRun(t)
defer RecordTestRun(t)

last := ""
expected := fmt.Sprintf(`SERVER NAME VERSION STATUS MESSAGE PROJECT
https://kubernetes.default.svc in-cluster %v Successful `, GetVersions().ServerVersion)

clusterFixture.
Given(t).
Project(ProjectName).
Project(ProjectName)

// We need an application targeting the cluster, otherwise the test will
// fail if run isolated.
app.GivenWithSameState(t).
Path(guestbookPath).
When().
List().
Then().
AndCLIOutput(func(output string, err error) {
assert.Equal(t, fmt.Sprintf(`SERVER NAME VERSION STATUS MESSAGE PROJECT
https://kubernetes.default.svc in-cluster %v Successful `, GetVersions().ServerVersion), output)
})
CreateApp()

tries := 2
for i := 0; i <= tries; i += 1 {
clusterFixture.GivenWithSameState(t).
When().
List().
Then().
AndCLIOutput(func(output string, err error) {
last = output
})
if expected == last {
break
} else if i < tries {
// We retry with a simple backoff
time.Sleep(time.Duration(i+1) * time.Second)
}
}
assert.Equal(t, expected, last)
}

func TestClusterAdd(t *testing.T) {
Expand Down

0 comments on commit 3d01b6d

Please sign in to comment.