MCPcopy Create free account
hub / github.com/bytebase/bytebase / waitDBPing

Function waitDBPing

backend/common/testcontainer/testcontainer.go:165–185  ·  view source on GitHub ↗
(ctx context.Context, db *sql.DB)

Source from the content-addressed store, hash-verified

163}
164
165func waitDBPing(ctx context.Context, db *sql.DB) error {
166 started := time.Now()
167 ticker := time.NewTicker(3 * time.Second)
168 defer ticker.Stop()
169 timeout := time.After(10 * time.Minute)
170outerLoop:
171 for {
172 select {
173 case <-ticker.C:
174 if err := db.PingContext(ctx); err == nil {
175 if time.Since(started) > 1*time.Minute {
176 fmt.Printf("Total wait time: %s\n", time.Since(started))
177 }
178 break outerLoop
179 }
180 case <-timeout:
181 return errors.Errorf("start container timeout reached")
182 }
183 }
184 return nil
185}
186
187// GetTestPgContainer is a helper function for tests that creates a PostgreSQL container
188// and handles the error by failing the test if container creation fails

Callers 5

GetTestMySQLContainerFunction · 0.85
getPgContainerWithImageFunction · 0.85
GetOracleContainerFunction · 0.85
GetMSSQLContainerFunction · 0.85
GetTiDBContainerFunction · 0.85

Calls 2

StopMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected