From 455fa04312a6f2548636fd7a5b6cf7fe939217d6 Mon Sep 17 00:00:00 2001 From: Charly Molter Date: Wed, 10 Jan 2024 03:25:48 +0100 Subject: [PATCH] test(e2e): avoid flake on postgres tests (#8788) 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 --- .../resilience_multizone_universal_postgres.go | 9 ++++++--- test/framework/testing.go | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/e2e_env/multizone/resilience/resilience_multizone_universal_postgres.go b/test/e2e_env/multizone/resilience/resilience_multizone_universal_postgres.go index adc517aae345..1c81a133540f 100644 --- a/test/e2e_env/multizone/resilience/resilience_multizone_universal_postgres.go +++ b/test/e2e_env/multizone/resilience/resilience_multizone_universal_postgres.go @@ -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)). diff --git a/test/framework/testing.go b/test/framework/testing.go index d349b4f3c44c..8bb9f7b7a91b 100644 --- a/test/framework/testing.go +++ b/test/framework/testing.go @@ -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 { @@ -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...)