chore: implement more robust wait strategies in testcontainers services

This commit is contained in:
Manuel de la Peña
2025-02-18 17:58:47 +01:00
parent d3c0d39dc8
commit 0c2d884898
7 changed files with 45 additions and 7 deletions

View File

@@ -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