diff --git a/clickhouse/clickhouse_test.go b/clickhouse/clickhouse_test.go index 30073f36..32de82d7 100644 --- a/clickhouse/clickhouse_test.go +++ b/clickhouse/clickhouse_test.go @@ -13,6 +13,7 @@ import ( "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/clickhouse" + "github.com/testcontainers/testcontainers-go/wait" ) const ( @@ -39,6 +40,14 @@ func getTestConnection(t testing.TB, cfg Config) (*Storage, error) { clickhouse.WithUsername(clickhouseUser), clickhouse.WithPassword(clickhousePass), clickhouse.WithDatabase(clickhouseDB), + testcontainers.WithWaitStrategy( + wait.ForAll( + wait.ForListeningPort("8123/tcp"), + wait.NewHTTPStrategy("/").WithPort("8123/tcp").WithStatusCodeMatcher(func(status int) bool { + return status == 200 + }), + ), + ), ) testcontainers.CleanupContainer(t, c) if err != nil { diff --git a/minio/minio_test.go b/minio/minio_test.go index 93f62a5e..89d1d1bb 100644 --- a/minio/minio_test.go +++ b/minio/minio_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/minio" + "github.com/testcontainers/testcontainers-go/wait" ) const ( @@ -34,6 +35,10 @@ func newTestStore(t testing.TB) (*Storage, error) { img, minio.WithUsername(minioUser), minio.WithPassword(minioPass), + testcontainers.WithWaitStrategy( + wait.ForListeningPort("9000/tcp"), + wait.ForHTTP("/minio/health/live").WithPort("9000"), + ), ) testcontainers.CleanupContainer(t, c) if err != nil { diff --git a/mongodb/mongodb_test.go b/mongodb/mongodb_test.go index a5187aaa..603110b9 100644 --- a/mongodb/mongodb_test.go +++ b/mongodb/mongodb_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mongodb" + "github.com/testcontainers/testcontainers-go/wait" ) const ( @@ -29,7 +30,15 @@ func newTestStore(t testing.TB) (*Storage, error) { ctx := context.Background() - c, err := mongodb.Run(ctx, img, mongodb.WithUsername(mongoDBUser), mongodb.WithPassword(mongoDBPass)) + c, err := mongodb.Run( + ctx, img, mongodb.WithUsername(mongoDBUser), mongodb.WithPassword(mongoDBPass), + testcontainers.WithWaitStrategy( + wait.ForAll( + wait.ForListeningPort("27017/tcp"), + wait.ForLog("Waiting for connections"), + ), + ), + ) testcontainers.CleanupContainer(t, c) if err != nil { return nil, err diff --git a/mysql/mysql_test.go b/mysql/mysql_test.go index 57f268e4..64e4262b 100644 --- a/mysql/mysql_test.go +++ b/mysql/mysql_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mysql" + "github.com/testcontainers/testcontainers-go/wait" ) const ( @@ -51,6 +52,10 @@ func mustStartMySQL(t testing.TB) *mysql.MySQLContainer { mysql.WithPassword(mysqlPass), mysql.WithUsername(mysqlUser), mysql.WithDatabase(mysqlDatabase), + testcontainers.WithWaitStrategy( + wait.ForListeningPort("3306/tcp"), + wait.ForLog("port: 3306 MySQL Community Server"), + ), ) testcontainers.CleanupContainer(t, c) require.NoError(t, err) diff --git a/neo4j/neo4j_test.go b/neo4j/neo4j_test.go index 7a6548bf..738e32b4 100644 --- a/neo4j/neo4j_test.go +++ b/neo4j/neo4j_test.go @@ -8,7 +8,9 @@ import ( "time" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/neo4j" + "github.com/testcontainers/testcontainers-go/wait" ) var testStore *Storage @@ -21,6 +23,13 @@ func TestMain(m *testing.M) { neo4jContainer, err := neo4j.Run(ctx, "neo4j:5.26", neo4j.WithAdminPassword("pass#w*#d"), + testcontainers.WithWaitStrategy( + wait.ForAll( + wait.ForListeningPort("7474/tcp"), + wait.ForListeningPort("7687/tcp"), + wait.ForLog("Bolt enabled on"), + ), + ), ) if err != nil { log.Fatalf("Failed to start Neo4j container: %v", err) diff --git a/postgres/postgres_test.go b/postgres/postgres_test.go index 85383b4f..4b7b5590 100644 --- a/postgres/postgres_test.go +++ b/postgres/postgres_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/postgres" - "github.com/testcontainers/testcontainers-go/wait" ) const ( @@ -36,11 +35,7 @@ func newTestStore(t testing.TB) (*Storage, error) { postgres.WithUsername(postgresUser), postgres.WithPassword(postgresPass), postgres.WithDatabase(postgresDatabase), - testcontainers.WithWaitStrategy( - // 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), - ), + postgres.BasicWaitStrategies(), ) testcontainers.CleanupContainer(t, c) require.NoError(t, err) diff --git a/s3/init_test.go b/s3/init_test.go index 9c9176af..f1f97771 100644 --- a/s3/init_test.go +++ b/s3/init_test.go @@ -6,7 +6,9 @@ import ( "testing" "time" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/minio" + "github.com/testcontainers/testcontainers-go/wait" ) const ( @@ -35,6 +37,10 @@ func TestMain(m *testing.M) { img, minio.WithUsername(minioUser), minio.WithPassword(minioPass), + testcontainers.WithWaitStrategy( + wait.ForListeningPort("9000/tcp"), + wait.ForHTTP("/minio/health/live").WithPort("9000"), + ), ) if err != nil { panic(err)