Skip to content

Commit

Permalink
fix(test): added additonal readiness checks for DB (#334)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Reimsbach <[email protected]>
  • Loading branch information
drochow and MR2011 authored Oct 28, 2024
1 parent 99964f5 commit 45390c4
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 41 deletions.
8 changes: 6 additions & 2 deletions internal/database/mariadb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ func TestConnection(cfg util.Config, backOff int) error {
}

//before each try wait 1 Second
time.Sleep(time.Millisecond * 1000)
time.Sleep(1 * time.Second)
connectionString := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?multiStatements=true&parseTime=true", cfg.DBUser, cfg.DBPassword, cfg.DBAddress, cfg.DBPort, cfg.DBName)
logrus.Info("Testing Connection to Database...")
db, err := sqlx.Connect("mysql", connectionString)
if err != nil {
return TestConnection(cfg, backOff-1)
}
defer db.Close()
//do an actual ping to check if not only the handshake works but the db schema is as well ready to operate on
err = db.Ping()
if err != nil {
return TestConnection(cfg, backOff-1)
}
return nil
}

Expand Down
4 changes: 0 additions & 4 deletions internal/database/mariadb/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
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"
Expand All @@ -23,8 +21,6 @@ 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()
Expand Down
6 changes: 6 additions & 0 deletions internal/database/mariadb/test/database_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ func (dbm *LocalTestDataBaseManager) NewTestSchema() *mariadb.SqlDatabase {
if err != nil {
ginkgo.GinkgoLogr.WithCallDepth(5).Error(err, "Failure while loading DB Client for new Schema")
}

err = mariadb.TestConnection(dbm.Config.Config, 10)
if err != nil {
ginkgo.GinkgoLogr.WithCallDepth(5).Error(err, "Failure while testing connection for new Schema")
}

return dbClient
}

Expand Down
10 changes: 4 additions & 6 deletions internal/e2e/activity_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package e2e_test
import (
"context"
"fmt"
"os"
"time"

"github.com/cloudoperators/heureka/internal/entity"
testentity "github.com/cloudoperators/heureka/internal/entity/test"
"github.com/cloudoperators/heureka/internal/util"
util2 "github.com/cloudoperators/heureka/pkg/util"
"os"

"github.com/cloudoperators/heureka/internal/api/graphql/graph/model"
"github.com/cloudoperators/heureka/internal/database/mariadb"
Expand All @@ -32,8 +30,6 @@ 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()
Expand Down Expand Up @@ -141,7 +137,9 @@ var _ = Describe("Getting Activities via API", Label("e2e", "Activity"), func()
ctx := context.Background()

err = client.Run(ctx, req, &respData)

if err != nil {
logrus.WithError(err).WithField("request", req).Info("Error while unmarshaling")
}
Expect(err).To(BeNil(), "Error while unmarshaling")
})

Expand Down
6 changes: 1 addition & 5 deletions internal/e2e/component_instance_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package e2e_test
import (
"context"
"fmt"
"os"
"time"

"github.com/cloudoperators/heureka/internal/entity"
testentity "github.com/cloudoperators/heureka/internal/entity/test"
"github.com/cloudoperators/heureka/internal/util"
util2 "github.com/cloudoperators/heureka/pkg/util"
"os"

"github.com/cloudoperators/heureka/internal/server"

Expand All @@ -32,8 +30,6 @@ 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()
Expand Down
6 changes: 1 addition & 5 deletions internal/e2e/component_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ package e2e_test
import (
"context"
"fmt"
"os"
"time"

"github.com/cloudoperators/heureka/internal/entity"
testentity "github.com/cloudoperators/heureka/internal/entity/test"
"os"

"github.com/cloudoperators/heureka/internal/util"
util2 "github.com/cloudoperators/heureka/pkg/util"
Expand All @@ -33,8 +31,6 @@ 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()
Expand Down
6 changes: 1 addition & 5 deletions internal/e2e/component_version_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package e2e_test
import (
"context"
"fmt"
"os"
"time"

"github.com/cloudoperators/heureka/internal/entity"
testentity "github.com/cloudoperators/heureka/internal/entity/test"
"github.com/cloudoperators/heureka/internal/util"
util2 "github.com/cloudoperators/heureka/pkg/util"
"os"

"github.com/cloudoperators/heureka/internal/server"

Expand All @@ -32,8 +30,6 @@ 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()
Expand Down
2 changes: 0 additions & 2 deletions internal/e2e/evidence_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ 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()
Expand Down
6 changes: 1 addition & 5 deletions internal/e2e/issue_match_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package e2e_test
import (
"context"
"fmt"
"os"
"time"

"github.com/cloudoperators/heureka/internal/entity"
testentity "github.com/cloudoperators/heureka/internal/entity/test"
"github.com/cloudoperators/heureka/internal/util"
util2 "github.com/cloudoperators/heureka/pkg/util"
"os"

"github.com/cloudoperators/heureka/internal/api/graphql/graph/model"
"github.com/cloudoperators/heureka/internal/database/mariadb/test"
Expand All @@ -29,8 +27,6 @@ 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()
Expand Down
2 changes: 0 additions & 2 deletions internal/e2e/issue_match_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ 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()
Expand Down
6 changes: 1 addition & 5 deletions internal/e2e/service_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package e2e_test
import (
"context"
"fmt"
"os"
"time"

"github.com/cloudoperators/heureka/internal/entity"
testentity "github.com/cloudoperators/heureka/internal/entity/test"
"github.com/cloudoperators/heureka/internal/util"
util2 "github.com/cloudoperators/heureka/pkg/util"
"os"

"github.com/cloudoperators/heureka/internal/server"

Expand All @@ -32,8 +30,6 @@ 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()
Expand Down

0 comments on commit 45390c4

Please sign in to comment.