From a1f5f5416865cd593ee6f2cea803c7b0068ee9a8 Mon Sep 17 00:00:00 2001 From: copyonwrite <73547592+copyonwrite@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:40:30 +0200 Subject: [PATCH] chore: add sleeps to suppress potential racing conditions which make tests fail. (#327) --- internal/database/mariadb/issue_test.go | 5 +++++ internal/e2e/activity_query_test.go | 5 +++++ internal/e2e/component_instance_query_test.go | 5 +++++ internal/e2e/component_query_test.go | 5 +++++ internal/e2e/component_version_query_test.go | 4 ++++ internal/e2e/evidence_query_test.go | 3 +++ internal/e2e/issue_match_change_test.go | 5 +++++ internal/e2e/issue_match_query_test.go | 4 ++++ internal/e2e/service_query_test.go | 6 +++++- 9 files changed, 41 insertions(+), 1 deletion(-) diff --git a/internal/database/mariadb/issue_test.go b/internal/database/mariadb/issue_test.go index b56db30b..1b18eaed 100644 --- a/internal/database/mariadb/issue_test.go +++ b/internal/database/mariadb/issue_test.go @@ -4,6 +4,8 @@ package mariadb_test import ( + "time" + "github.com/cloudoperators/heureka/internal/database/mariadb" "github.com/cloudoperators/heureka/internal/database/mariadb/test" "github.com/cloudoperators/heureka/internal/entity" @@ -21,6 +23,9 @@ var _ = Describe("Issue", Label("database", "Issue"), func() { var db *mariadb.SqlDatabase var seeder *test.DatabaseSeeder BeforeEach(func() { + // This sleep suppresses a potential racing condition which triggers test failures. + time.Sleep(3 * time.Second) + var err error db = dbm.NewTestSchema() seeder, err = test.NewDatabaseSeeder(dbm.DbConfig()) diff --git a/internal/e2e/activity_query_test.go b/internal/e2e/activity_query_test.go index af6ed051..ce9df42b 100644 --- a/internal/e2e/activity_query_test.go +++ b/internal/e2e/activity_query_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "os" + "time" "github.com/cloudoperators/heureka/internal/entity" testentity "github.com/cloudoperators/heureka/internal/entity/test" @@ -31,6 +32,9 @@ var _ = Describe("Getting Activities via API", Label("e2e", "Activity"), func() var cfg util.Config BeforeEach(func() { + // This sleep suppresses a potential racing condition which triggers test failures. + time.Sleep(3 * time.Second) + var err error _ = dbm.NewTestSchema() seeder, err = test.NewDatabaseSeeder(dbm.DbConfig()) @@ -133,6 +137,7 @@ var _ = Describe("Getting Activities via API", Label("e2e", "Activity"), func() req.Var("after", "0") req.Header.Set("Cache-Control", "no-cache") + ctx := context.Background() err = client.Run(ctx, req, &respData) diff --git a/internal/e2e/component_instance_query_test.go b/internal/e2e/component_instance_query_test.go index 68eed095..ea51c2f0 100644 --- a/internal/e2e/component_instance_query_test.go +++ b/internal/e2e/component_instance_query_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "os" + "time" "github.com/cloudoperators/heureka/internal/entity" testentity "github.com/cloudoperators/heureka/internal/entity/test" @@ -31,6 +32,9 @@ var _ = Describe("Getting ComponentInstances via API", Label("e2e", "ComponentIn var cfg util.Config BeforeEach(func() { + // This sleep suppresses a potential racing condition which triggers test failures. + time.Sleep(3 * time.Second) + var err error _ = dbm.NewTestSchema() seeder, err = test.NewDatabaseSeeder(dbm.DbConfig()) @@ -135,6 +139,7 @@ var _ = Describe("Getting ComponentInstances via API", Label("e2e", "ComponentIn req.Var("after", "0") req.Header.Set("Cache-Control", "no-cache") + ctx := context.Background() err = client.Run(ctx, req, &respData) diff --git a/internal/e2e/component_query_test.go b/internal/e2e/component_query_test.go index 0837ed4f..16f63429 100644 --- a/internal/e2e/component_query_test.go +++ b/internal/e2e/component_query_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "os" + "time" "github.com/cloudoperators/heureka/internal/entity" testentity "github.com/cloudoperators/heureka/internal/entity/test" @@ -32,6 +33,9 @@ var _ = Describe("Getting Components via API", Label("e2e", "Components"), func( var cfg util.Config BeforeEach(func() { + // This sleep suppresses a potential racing condition which triggers test failures. + time.Sleep(3 * time.Second) + var err error _ = dbm.NewTestSchema() seeder, err = test.NewDatabaseSeeder(dbm.DbConfig()) @@ -136,6 +140,7 @@ var _ = Describe("Getting Components via API", Label("e2e", "Components"), func( req.Var("after", "0") req.Header.Set("Cache-Control", "no-cache") + ctx := context.Background() err = client.Run(ctx, req, &respData) diff --git a/internal/e2e/component_version_query_test.go b/internal/e2e/component_version_query_test.go index 92fa8dd9..cf29d47b 100644 --- a/internal/e2e/component_version_query_test.go +++ b/internal/e2e/component_version_query_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "os" + "time" "github.com/cloudoperators/heureka/internal/entity" testentity "github.com/cloudoperators/heureka/internal/entity/test" @@ -31,6 +32,9 @@ var _ = Describe("Getting ComponentVersions via API", Label("e2e", "ComponentVer var cfg util.Config BeforeEach(func() { + // This sleep suppresses a potential racing condition which triggers test failures. + time.Sleep(3 * time.Second) + var err error _ = dbm.NewTestSchema() seeder, err = test.NewDatabaseSeeder(dbm.DbConfig()) diff --git a/internal/e2e/evidence_query_test.go b/internal/e2e/evidence_query_test.go index 6a2f86b4..afdce61d 100644 --- a/internal/e2e/evidence_query_test.go +++ b/internal/e2e/evidence_query_test.go @@ -32,6 +32,9 @@ var _ = Describe("Getting Evidences via API", Label("e2e", "Evidences"), func() var cfg util.Config BeforeEach(func() { + // This sleep suppresses a potential racing condition which triggers test failures. + time.Sleep(3 * time.Second) + var err error _ = dbm.NewTestSchema() seeder, err = test.NewDatabaseSeeder(dbm.DbConfig()) diff --git a/internal/e2e/issue_match_change_test.go b/internal/e2e/issue_match_change_test.go index 82bdf998..eea4eaba 100644 --- a/internal/e2e/issue_match_change_test.go +++ b/internal/e2e/issue_match_change_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "os" + "time" "github.com/cloudoperators/heureka/internal/entity" testentity "github.com/cloudoperators/heureka/internal/entity/test" @@ -28,6 +29,9 @@ var _ = Describe("Getting IssueMatchChanges via API", Label("e2e", "IssueMatchCh var s *server.Server var cfg util.Config BeforeEach(func() { + // This sleep suppresses a potential racing condition which triggers test failures. + time.Sleep(3 * time.Second) + var err error _ = dbm.NewTestSchema() seeder, err = test.NewDatabaseSeeder(dbm.DbConfig()) @@ -132,6 +136,7 @@ var _ = Describe("Getting IssueMatchChanges via API", Label("e2e", "IssueMatchCh req.Var("after", "0") req.Header.Set("Cache-Control", "no-cache") + ctx := context.Background() err = client.Run(ctx, req, &respData) diff --git a/internal/e2e/issue_match_query_test.go b/internal/e2e/issue_match_query_test.go index 84c1606f..284d3801 100644 --- a/internal/e2e/issue_match_query_test.go +++ b/internal/e2e/issue_match_query_test.go @@ -31,6 +31,9 @@ var _ = Describe("Getting IssueMatches via API", Label("e2e", "IssueMatches"), f var s *server.Server var cfg util.Config BeforeEach(func() { + // This sleep suppresses a potential racing condition which triggers test failures. + time.Sleep(3 * time.Second) + var err error _ = dbm.NewTestSchema() seeder, err = test.NewDatabaseSeeder(dbm.DbConfig()) @@ -134,6 +137,7 @@ var _ = Describe("Getting IssueMatches via API", Label("e2e", "IssueMatches"), f req.Var("after", "0") req.Header.Set("Cache-Control", "no-cache") + ctx := context.Background() err = client.Run(ctx, req, &respData) diff --git a/internal/e2e/service_query_test.go b/internal/e2e/service_query_test.go index 29d3bcaa..04ef7ab2 100644 --- a/internal/e2e/service_query_test.go +++ b/internal/e2e/service_query_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "os" + "time" "github.com/cloudoperators/heureka/internal/entity" testentity "github.com/cloudoperators/heureka/internal/entity/test" @@ -31,6 +32,9 @@ var _ = Describe("Getting Services via API", Label("e2e", "Services"), func() { var cfg util.Config BeforeEach(func() { + // This sleep suppresses a potential racing condition which triggers test failures. + time.Sleep(3 * time.Second) + var err error _ = dbm.NewTestSchema() seeder, err = test.NewDatabaseSeeder(dbm.DbConfig()) @@ -39,7 +43,6 @@ var _ = Describe("Getting Services via API", Label("e2e", "Services"), func() { cfg = dbm.DbConfig() cfg.Port = util2.GetRandomFreePort() s = server.NewServer(cfg) - s.NonBlockingStart() }) @@ -174,6 +177,7 @@ var _ = Describe("Getting Services via API", Label("e2e", "Services"), func() { req.Var("after", "0") req.Header.Set("Cache-Control", "no-cache") + ctx := context.Background() err = client.Run(ctx, req, &respData)