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

chore: resolve IPv4-IPv6 issues

Open mdelapenya opened this issue 1 year ago • 2 comments

  • feat: detect IPv4 and IPv6
  • chore: get container host from the hostIPs
  • chore: simplify
  • chore: resolve host port bindings
  • chore: get bound ports from port bindings
  • chore: update wait strategies to use bound ports
  • chore: lint
  • fix: use a fixed port

What does this PR do?

It looks up the bounded ports every time a container needs to get a mapped port. It also improves the wait strategies (http and host-port) to get the bound port.

To get the bound port, we'll get the host IP addresses from the current Docker Host, and with that list of values, and the ports from a container, we will get the bound ports.

Finally, we are deprecating the ForceIPv4LocalHost field from the HTTPStrategy, as it's not needed anymore. The example test is updated to fix the port in the wait strategy.

Why is it important?

Resolves flakiness in the CI, as the testable example is failing in a non consistent manner: because the test exposes two ports, 8080 and 80, the way Docker is retrieving them from the JSON representation is not deterministic (it's a port map), therefore, the test is sometimes returning the 80 port for getting the HTTP endpoint and others, the 8080 port.

At the same time, it adds a more consistent manner of getting the host and the port, relying on the Docker host, taking into consideration the IPv4 and IPv6 families.

Related issues

  • Relates #1775

mdelapenya avatar Mar 19 '24 18:03 mdelapenya

Deploy Preview for testcontainers-go ready!

Name Link
Latest commit 81fcba6dafc9f306b113e9ff3b3d94a0d5a3e76d
Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/663c984d0945110008b81049
Deploy Preview https://deploy-preview-2403--testcontainers-go.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Mar 19 '24 18:03 netlify[bot]

@cristianrgreco I ping you as you already implemented this for NodeJS, and I used it as reference. Could you please take a look? 🙏

mdelapenya avatar Apr 18 '24 21:04 mdelapenya