Retry Logic to Mssql Tests [VAULT-637] (#10039)

* added retry to mssql testing

* setting num retry to 3

* removed a comment and moved svc into loop

Co-authored-by: HridoyRoy <hridoyroy@Hridoys-MacBook-Pro.local>
Co-authored-by: HridoyRoy <hridoyroy@Hridoys-MBP.hitronhub.home>
This commit is contained in:
Hridoy Roy 2020-09-28 09:03:23 -07:00 committed by GitHub
parent 98fe5029b0
commit d7a673321d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,28 +13,38 @@ import (
const mssqlPassword = "yourStrong(!)Password" const mssqlPassword = "yourStrong(!)Password"
// This constant is used in retrying the mssql container restart, since
// intermittently the container starts but mssql within the container
// is unreachable.
const numRetries = 3
func PrepareMSSQLTestContainer(t *testing.T) (cleanup func(), retURL string) { func PrepareMSSQLTestContainer(t *testing.T) (cleanup func(), retURL string) {
if os.Getenv("MSSQL_URL") != "" { if os.Getenv("MSSQL_URL") != "" {
return func() {}, os.Getenv("MSSQL_URL") return func() {}, os.Getenv("MSSQL_URL")
} }
runner, err := docker.NewServiceRunner(docker.RunOptions{ var err error
ContainerName: "sqlserver", for i := 0; i < numRetries; i++ {
ImageRepo: "mcr.microsoft.com/mssql/server", var svc *docker.Service
ImageTag: "2017-latest-ubuntu", runner, err := docker.NewServiceRunner(docker.RunOptions{
Env: []string{"ACCEPT_EULA=Y", "SA_PASSWORD=" + mssqlPassword}, ContainerName: "sqlserver",
Ports: []string{"1433/tcp"}, ImageRepo: "mcr.microsoft.com/mssql/server",
}) ImageTag: "2017-latest-ubuntu",
if err != nil { Env: []string{"ACCEPT_EULA=Y", "SA_PASSWORD=" + mssqlPassword},
t.Fatalf("Could not start docker MSSQL: %s", err) Ports: []string{"1433/tcp"},
})
if err != nil {
t.Fatalf("Could not start docker MSSQL: %s", err)
}
svc, err = runner.StartService(context.Background(), connectMSSQL)
if err == nil {
return svc.Cleanup, svc.Config.URL().String()
}
} }
svc, err := runner.StartService(context.Background(), connectMSSQL) t.Fatalf("Could not start docker MSSQL: %s", err)
if err != nil { return nil, ""
t.Fatalf("Could not start docker MSSQL: %s", err)
}
return svc.Cleanup, svc.Config.URL().String()
} }
func connectMSSQL(ctx context.Context, host string, port int) (docker.ServiceConfig, error) { func connectMSSQL(ctx context.Context, host string, port int) (docker.ServiceConfig, error) {