diff --git a/modules/redpanda/redpanda.go b/modules/redpanda/redpanda.go index 7f46617536..3ed3932066 100644 --- a/modules/redpanda/redpanda.go +++ b/modules/redpanda/redpanda.go @@ -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, } @@ -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) } @@ -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) } @@ -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 }