Skip to content

Commit

Permalink
Merge pull request #154 from itaischwartz/#149-wait-for-reaper-listen…
Browse files Browse the repository at this point in the history
…ing-port

Fix reaper connect failure by waiting for listening port
  • Loading branch information
gianarb authored Mar 3, 2020
2 parents f64b20d + f518b5c commit bae9fd8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bufio"
"context"
"fmt"
"github.com/docker/go-connections/nat"
"github.com/testcontainers/testcontainers-go/wait"
"net"
"strings"
"time"
Expand Down Expand Up @@ -39,11 +41,12 @@ func NewReaper(ctx context.Context, sessionID string, provider ReaperProvider, r
SessionID: sessionID,
}

// TODO: reuse reaper if there already is one
listeningPort := nat.Port("8080/tcp")

// TODO: reuse reaper if there already is one
req := ContainerRequest{
Image: reaperImage(reaperImageName),
ExposedPorts: []string{"8080"},
ExposedPorts: []string{string(listeningPort)},
Labels: map[string]string{
TestcontainerLabel: "true",
TestcontainerLabelIsReaper: "true",
Expand All @@ -53,6 +56,7 @@ func NewReaper(ctx context.Context, sessionID string, provider ReaperProvider, r
"/var/run/docker.sock": "/var/run/docker.sock",
},
AutoRemove: true,
WaitingFor: wait.ForListeningPort(listeningPort),
}

c, err := provider.RunContainer(ctx, req)
Expand Down

0 comments on commit bae9fd8

Please sign in to comment.