Skip to content

Commit

Permalink
feat: add a configuration option for time to wait map port
Browse files Browse the repository at this point in the history
  • Loading branch information
Willian S. de Souza authored and wilsouza committed May 25, 2024
1 parent 29e05e4 commit c5fb1e2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ echo '' > /etc/confluent/docker/ensure
// }
)

var timeToWaitUntilContainerMapPorts = time.Second

// KafkaContainer represents the Kafka container type used in the module
type KafkaContainer struct {
testcontainers.Container
Expand Down Expand Up @@ -71,7 +73,7 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
// it is a workaround for the container is not exposing the port yet
// ref. https://github.com/testcontainers/testcontainers-go/issues/2543
// wait for the container port to be exposed
time.Sleep(time.Second)
time.Sleep(timeToWaitUntilContainerMapPorts)

host, err := c.Host(ctx)
if err != nil {
Expand Down Expand Up @@ -139,6 +141,13 @@ func WithClusterID(clusterID string) testcontainers.CustomizeRequestOption {
}
}

func WithTimeWaitUntilContainerMapPorts(timeWait time.Duration) testcontainers.CustomizeRequestOption {
timeToWaitUntilContainerMapPorts = timeWait
return func(req *testcontainers.GenericContainerRequest) error {
return nil
}
}

// Brokers retrieves the broker connection strings from Kafka with only one entry,
// defined by the exposed public port.
func (kc *KafkaContainer) Brokers(ctx context.Context) ([]string, error) {
Expand Down

0 comments on commit c5fb1e2

Please sign in to comment.