Skip to content

Commit

Permalink
test(e2e): avoid flake on postgres tests (#8788)
Browse files Browse the repository at this point in the history
Looks like in some cases the containers are not fully
removed before we create the new ones. We make sure to use
different container names to avoid these kind of flakes

Signed-off-by: Charly Molter <[email protected]>
  • Loading branch information
lahabana authored Jan 10, 2024
1 parent 29b725e commit 455fa04
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ import (
)

func ResilienceMultizoneUniversalPostgres() {
const clusterName1 = "kuma-respos1"
const clusterName2 = "kuma-respos2"
var clusterName1 string
var clusterName2 string

var global, zoneUniversal Cluster

BeforeEach(func() {
testingT := NewTestingT()
clusterName1 = "kuma1-" + testingT.Hash()
clusterName2 = "kuma2-" + testingT.Hash()
// Global
global = NewUniversalCluster(NewTestingT(), clusterName1, Verbose)
global = NewUniversalCluster(testingT, clusterName1, Verbose)

err := NewClusterSetup().
Install(postgres.Install(clusterName1)).
Expand Down
9 changes: 9 additions & 0 deletions test/framework/testing.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package framework

import (
"hash/fnv"

"github.com/gruntwork-io/terratest/modules/logger"
"github.com/onsi/ginkgo/v2"
"k8s.io/apimachinery/pkg/util/rand"
)

type TestingT struct {
Expand All @@ -21,6 +24,12 @@ func (i *TestingT) Name() string {
return i.desc.FullText()
}

func (i *TestingT) Hash() string {
hash := fnv.New32()
_, _ = hash.Write([]byte(i.Name()))
return rand.SafeEncodeString(string(hash.Sum(nil)))
}

// Logf logs a test progress message.
func Logf(format string, args ...interface{}) {
logger.Default.Logf(ginkgo.GinkgoT(), format, args...)
Expand Down

0 comments on commit 455fa04

Please sign in to comment.