Skip to content

Commit

Permalink
Add new waiting strategy for mongodb replicaset
Browse files Browse the repository at this point in the history
  • Loading branch information
smgt committed Sep 11, 2024
1 parent a8f842b commit 6106a6c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mongodb
import (
"context"
"fmt"
"time"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
Expand Down Expand Up @@ -87,6 +88,10 @@ func WithPassword(password string) testcontainers.CustomizeRequestOption {
func WithReplicaSet(replSetName string) testcontainers.CustomizeRequestOption {
return func(req *testcontainers.GenericContainerRequest) error {
req.Cmd = append(req.Cmd, "--replSet", replSetName)
req.WaitingFor = wait.ForAll(
wait.ForExec(eval("rs.status().ok")),
wait.ForListeningPort("27017/tcp"),
).WithDeadline(60 * time.Second)
req.LifecycleHooks = append(req.LifecycleHooks, testcontainers.ContainerLifecycleHooks{
PostStarts: []testcontainers.ContainerHook{
func(ctx context.Context, c testcontainers.Container) error {
Expand Down

0 comments on commit 6106a6c

Please sign in to comment.