testcontainers-go icon indicating copy to clipboard operation
testcontainers-go copied to clipboard

[Enhancement]: the elasticsearch configurable timeout

Open james-async opened this issue 8 months ago • 1 comments

Proposal

The elasticsearch module should support the client applying a custom StartupTimeout.

In resource constrained environments as seen in some (many?) Github Actions it can take longer for the container to complete the WaitFor strategy. By allowing the client to specify the timeout they can control how long their system is willing to wait.

This module currently does support the client passing in additional strategies. However, the StartupTimeout needs to be applied to the wait.ForHTTP strategy.

The logs as seen from a timeout include the following where it can be seen that no timeout is applied to the wait.ForHTTP("/"):

Waiting for: &{timeout: Port:9200 Path:/ StatusCodeMatcher:0x1b9b0c0 ResponseMatcher:0x1c0e9e0 UseTLS:false AllowInsecure:false TLSConfig: Method:GET Body: Headers:map[] ResponseHeadersMatcher:0x1c0ea00 PollInterval:100ms UserInfo:elastic:changeme ForceIPv4LocalHost:false}ELASTIC: container logs (wait until ready: context deadline exceeded):

This module could be updated to include an additional option:

// WithStartupTimeout sets the timeout duration used when waiting for the Elasticsearch container to start.
func WithStartupTimeout(timeout time.Duration) Option {
	return func(o *Options) {
		o.StartupTimeout = timeout
	}
}

and then apply the option in the setWaitFor function. Here I have setup no default StartupTimeout, but one could be applied to the defaultOptions, and then skip the if condition here:

if options.StartupTimeout > 0 {
	waitHTTP = waitHTTP.WithStartupTimeout(options.StartupTimeout)
}

james-async avatar Feb 14 '25 16:02 james-async