question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with 'withExposedPorts' using multiple ports

See original GitHub issue

addExposedPorts uses an array to set the exposedPorts declared as LinkedHashSet, so it maintains the order of insertions. However, withExposedPorts, uses Lists.newArrayList(ports) which internally calls Collections.addAll(…) which does not maintain the order of insertaion. The result is unexpected behaviour, in particular, an issue when setting the waitingFor strategy.
For instance, say we call: withExposedPorts(8080,1234) and then set waiting strategy as: Wait.forHttp(...) If Collections decides to place 1234 first, then the code will listen using port 1234, instead of 8080.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ofirgrmcommented, Oct 1, 2021

I assumed there was an order guaranteed since the ports are stored using LinkedHashSet. Using forPort will definitely solve the issue I’m having, so thanks for that! @bsideup, I think adding a line of documentation about it at https://www.testcontainers.org/features/startup_and_waits/ can be very useful.

Thanks.

0reactions
ZdrOStiwacommented, Jul 6, 2022

I just run into the same problem. I don’t think this has been clearly documented. Maybe reopen?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wait only for some of ports · Issue #933 - GitHub
When using testcontainers this way: new GenericContainer("shopify/toxiproxy") .withExposedPorts(8474, 3305); it is waiting for port 3305 to ...
Read more >
Why you should never use fixed ports in your Testcontainers ...
Bind for 0.0.0.0:80 failed: port is already allocated. But there is more - localhost is the king! There was some disturbance back in...
Read more >
Java Testcontainers - Cannot connect to exposed port
So I started to port those tests to TestContainers using my POP3 Server image as a GenericContainer and starting my POP3 Client classes...
Read more >
Networking and communicating with containers - Testcontainers
Generally, each required port needs to be explicitly exposed. For example, we can specify one or more ports as follows: Exposing ports.
Read more >
GenericContainer (TestContainers Core 1.3.0 API) - Javadoc.io
Get the actual mapped port for a given port exposed by the container. ... Allow container startup to be attempted more than once...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found