(ctx context.Context, db *sql.DB)
| 163 | } |
| 164 | |
| 165 | func 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) |
| 170 | outerLoop: |
| 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 |
no test coverage detected