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

fix(redpanda): race condition on port check #2692

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
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
19 changes: 14 additions & 5 deletions modules/redpanda/redpanda.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
"--smp=1",
"--memory=1G",
},
WaitingFor: wait.ForAll(
// Wait for the ports to be exposed only as the container needs configuration
// before it will bind to the ports and be ready to serve requests.
wait.ForListeningPort(defaultKafkaAPIPort).SkipInternalCheck(),
wait.ForListeningPort(defaultAdminAPIPort).SkipInternalCheck(),
wait.ForListeningPort(defaultSchemaRegistryPort).SkipInternalCheck(),
),
},
Started: true,
}
Expand Down Expand Up @@ -119,7 +126,7 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom

// 4. Register extra kafka listeners if provided, network aliases will be
// set
if err := registerListeners(ctx, settings, req); err != nil {
if err := registerListeners(settings, req); err != nil {
return nil, fmt.Errorf("failed to register listeners: %w", err)
}

Expand Down Expand Up @@ -200,11 +207,13 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
return nil, fmt.Errorf("failed to copy redpanda.yaml into container: %w", err)
}

// 8. Wait until Redpanda is ready to serve requests
// 8. Wait until Redpanda is ready to serve requests.
err = wait.ForAll(
wait.ForListeningPort(defaultKafkaAPIPort),
wait.ForLog("Successfully started Redpanda!").WithPollInterval(100*time.Millisecond)).
WaitUntilReady(ctx, container)
wait.ForListeningPort(defaultAdminAPIPort),
wait.ForListeningPort(defaultSchemaRegistryPort),
wait.ForLog("Successfully started Redpanda!"),
).WaitUntilReady(ctx, container)
if err != nil {
return nil, fmt.Errorf("failed to wait for Redpanda readiness: %w", err)
}
Expand Down Expand Up @@ -299,7 +308,7 @@ func renderBootstrapConfig(settings options) ([]byte, error) {

// registerListeners validates that the provided listeners are valid and set network aliases for the provided addresses.
// The container must be attached to at least one network.
func registerListeners(ctx context.Context, settings options, req testcontainers.GenericContainerRequest) error {
func registerListeners(settings options, req testcontainers.GenericContainerRequest) error {
if len(settings.Listeners) == 0 {
return nil
}
Expand Down
Loading