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:
parent
98fe5029b0
commit
d7a673321d
|
@ -13,11 +13,19 @@ import (
|
|||
|
||||
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) {
|
||||
if os.Getenv("MSSQL_URL") != "" {
|
||||
return func() {}, os.Getenv("MSSQL_URL")
|
||||
}
|
||||
|
||||
var err error
|
||||
for i := 0; i < numRetries; i++ {
|
||||
var svc *docker.Service
|
||||
runner, err := docker.NewServiceRunner(docker.RunOptions{
|
||||
ContainerName: "sqlserver",
|
||||
ImageRepo: "mcr.microsoft.com/mssql/server",
|
||||
|
@ -29,12 +37,14 @@ func PrepareMSSQLTestContainer(t *testing.T) (cleanup func(), retURL string) {
|
|||
t.Fatalf("Could not start docker MSSQL: %s", err)
|
||||
}
|
||||
|
||||
svc, err := runner.StartService(context.Background(), connectMSSQL)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
return svc.Cleanup, svc.Config.URL().String()
|
||||
t.Fatalf("Could not start docker MSSQL: %s", err)
|
||||
return nil, ""
|
||||
}
|
||||
|
||||
func connectMSSQL(ctx context.Context, host string, port int) (docker.ServiceConfig, error) {
|
||||
|
|
Loading…
Reference in New Issue