waitForSqlServerToStart polls the specified database to wait for it to become available, pausing between retry attempts, and returning an error if it is not able to verify that the database is available.
(dsn string)
| 77 | // between retry attempts, and returning an error if it is not able to verify that the database is |
| 78 | // available. |
| 79 | func waitForSqlServerToStart(dsn string) error { |
| 80 | fmt.Printf("Waiting for server to start...\n") |
| 81 | ctx := context.Background() |
| 82 | for counter := 0; counter < 30; counter++ { |
| 83 | conn, err := pgx.Connect(ctx, dsn) |
| 84 | if err == nil { |
| 85 | err = conn.Ping(ctx) |
| 86 | conn.Close(ctx) |
| 87 | if err == nil { |
| 88 | return nil |
| 89 | } |
| 90 | } |
| 91 | fmt.Printf("not up yet; waiting...\n") |
| 92 | time.Sleep(500 * time.Millisecond) |
| 93 | } |
| 94 | |
| 95 | return nil |
| 96 | } |
no test coverage detected