add retry logic in ldap.PrepareTestContainer (#27617)

This commit is contained in:
Marc Boudreau
2024-07-02 10:47:32 -04:00
committed by GitHub
parent 64ce6e74da
commit 8f26f19950

View File

@@ -49,6 +49,9 @@ func PrepareTestContainer(t *testing.T, version string) (cleanup func(), cfg *ld
cfg.RequestTimeout = 60 cfg.RequestTimeout = 60
cfg.MaximumPageSize = 1000 cfg.MaximumPageSize = 1000
var started bool
for i := 0; i < 3; i++ {
svc, err := runner.StartService(context.Background(), func(ctx context.Context, host string, port int) (docker.ServiceConfig, error) { svc, err := runner.StartService(context.Background(), func(ctx context.Context, host string, port int) (docker.ServiceConfig, error) {
connURL := fmt.Sprintf("ldap://%s:%d", host, port) connURL := fmt.Sprintf("ldap://%s:%d", host, port)
cfg.Url = connURL cfg.Url = connURL
@@ -71,13 +74,22 @@ func PrepareTestContainer(t *testing.T, version string) (cleanup func(), cfg *ld
t.Logf("could not start local LDAP docker container: %s", err) t.Logf("could not start local LDAP docker container: %s", err)
t.Log("Docker container logs: ") t.Log("Docker container logs: ")
t.Log(logsWriter.String()) t.Log(logsWriter.String())
t.FailNow() continue
} }
return func() { started = true
cleanup = func() {
if t.Failed() { if t.Failed() {
t.Log(logsWriter.String()) t.Log(logsWriter.String())
} }
svc.Cleanup() svc.Cleanup()
}, cfg }
break
}
if !started {
t.FailNow()
}
return cleanup, cfg
} }