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

fix(influxdb): Respect custom waitStrategy

Open marcinmilewski93 opened this issue 1 year ago • 1 comments

What does this PR do?

The purpose of this PR is to respect the provided waitStrategy for the InfluxDB container, rather than overriding it by default. This change allows the use of a custom waitStrategy when specified; if none is provided, the default waitStrategy will be applied, maintaining the same configuration as before this modification.

Why is it important?

In the current implementation, it's not possible to use a custom waitStrategy and in my case the default strategy marks the container as ready too early. The container is still not ready to receive writes as you can see below. Customizing the waitStrategy for example to check the /health status solved this issue. Example log output when container is not ready yet:

2024/10/22 10:38:54 ✅ Container started: d5d6612ccd27
2024/10/22 10:38:54 ⏳ Waiting for container id d5d6612ccd27 image: influxdb:2.0.7. Waiting for: &{timeout:<nil> Log:Listening log_id=[0-9a-zA-Z_~]+ service=tcp-listener transport=http IsRegexp:true Occurrence:1 PollInterval:100ms}
2024/10/22 10:39:04 🔔 Container is ready: d5d6612ccd27
2024-10-22T10:39:23.408+07:00|2|ERROR||,,,testing-invalid|9469|goroutine:1783|internal/runner.go:93|Post "http://localhost:49155/api/v2/write?bucket=bucket1&org=influxdata&precision=ns": read tcp [::1]:43726->[::1]:49155: read: connection reset by peer
2024/10/22 10:39:24 [E]! Write error: Post "http://localhost:49155/api/v2/write?bucket=lbucket1&org=influxdata&precision=ns": read tcp [::1]:55852->[::1]:49155: read: connection reset by peer
2024/10/22 10:39:24 unable to send metrics to InfluxDB. err=Post "http://localhost:49155/api/v2/write?bucket=bucket1&org=influxdata&precision=ns": read tcp [::1]:55852->[::1]:49155: read: connection reset by peer

After this modification different strategy could be employed, for example, to verify if InfluxDB is ready for queries and writes as you can see on below health check response:

{
  "name": "influxdb",
  "message": "ready for queries and writes",
  "status": "pass",
  "checks": [],
  "version": "2.0.7",
  "commit": "2a45f0c037"
}

Related issues

  • None

How to test this PR

I have added a test that uses a custom waitStrategy to verify this behavior.

marcinmilewski93 avatar Oct 22 '24 08:10 marcinmilewski93