blob: 92dc3f6ec63c718a2161f9612014265a032a878a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package postgres
import (
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
// BasicWaitStrategies is a simple but reliable way to wait for postgres to start.
// It returns a two-step wait strategy:
//
// - It will wait for the container to log `database system is ready to accept connections` twice, because it will restart itself after the first startup.
// - It will then wait for docker to actually serve the port on localhost.
// For non-linux OSes like Mac and Windows, Docker or Rancher Desktop will have to start a separate proxy.
// Without this, the tests will be flaky on those OSes!
func BasicWaitStrategies() testcontainers.CustomizeRequestOption {
// waitStrategy {
return testcontainers.WithAdditionalWaitStrategy(
// First, we wait for the container to log readiness twice.
// This is because it will restart itself after the first startup.
wait.ForLog("database system is ready to accept connections").WithOccurrence(2),
// Then, we wait for docker to actually serve the port on localhost.
// For non-linux OSes like Mac and Windows, Docker or Rancher Desktop will have to start a separate proxy.
// Without this, the tests will be flaky on those OSes!
wait.ForListeningPort("5432/tcp"),
)
// }
}
|