Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid race conditions by waiting one polling interval #1697

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions wait/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge

var mappedPort nat.Port
if ws.Port == "" {
ports, err := target.Ports(ctx)
for err != nil {
var err error
var ports nat.PortMap
// we wait one polling interval before we grab the ports otherwise they might not be bound yet on startup
for err != nil || ports == nil {
select {
case <-ctx.Done():
return fmt.Errorf("%w: %w", ctx.Err(), err)
Expand Down
9 changes: 6 additions & 3 deletions wait/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ func TestHttpStrategyFailsWhileGettingPortDueToNoExposedPorts(t *testing.T) {
},
StateImpl: func(_ context.Context) (*types.ContainerState, error) {
return &types.ContainerState{
Status: "running",
Status: "running",
Running: true,
mdelapenya marked this conversation as resolved.
Show resolved Hide resolved
}, nil
},
PortsImpl: func(ctx context.Context) (nat.PortMap, error) {
Expand Down Expand Up @@ -602,7 +603,8 @@ func TestHttpStrategyFailsWhileGettingPortDueToOnlyUDPPorts(t *testing.T) {
},
StateImpl: func(_ context.Context) (*types.ContainerState, error) {
return &types.ContainerState{
Status: "running",
Running: true,
Status: "running",
}, nil
},
PortsImpl: func(ctx context.Context) (nat.PortMap, error) {
Expand Down Expand Up @@ -649,7 +651,8 @@ func TestHttpStrategyFailsWhileGettingPortDueToExposedPortNoBindings(t *testing.
},
StateImpl: func(_ context.Context) (*types.ContainerState, error) {
return &types.ContainerState{
Status: "running",
Running: true,
Status: "running",
}, nil
},
PortsImpl: func(ctx context.Context) (nat.PortMap, error) {
Expand Down
Loading