forked from testcontainers/testcontainers-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait robustness (testcontainers#504)
Refactor port awaits for improved robustness: * We now allow a list of multiple startup liveness check ports to be defined for a container. This helps, e.g. for the browser containers, and lets us wait for both Selenium and VNC ports to be listening. I think this will help eliminate random flapping tests in this area and should fix testcontainers#466 * For exposed/bound ports, we now check that the port is accepting connections both (1) from within the container, and (2) from the testcontainers host. Previously, the internal check was done for Docker on Mac/Win and the external check for Linux. Now both are used for all environments, which simplifies the logic and gives a solid guarantee that the port truly is listening. (For reference, the internal check was done due to issues with the Docker networking stack opening a listening socket before the containerized service itself was listening). * Also, we now have a WaitAllStrategy that lets more than one wait strategy be used. For browser containers, we now wait for (a) a log message, and (b) the listening ports to be available. * Broken out some aspects of the wait strategies/port detection into separate classes and used this to help improve test coverage. * Refactored/tidied some code in network link configuration that was redundant, using Docker API filters instead of streamed filtering of containers
- 1.16.0
- 1.15.3
- 1.15.2
- 1.15.1
- 1.15.0
- 1.15.0-rc2
- 1.15.0-rc1
- 1.14.3
- 1.14.2
- 1.14.1
- 1.14.0
- 1.13.0
- 1.12.5
- 1.12.4
- 1.12.3
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.4
- 1.11.3
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.7
- 1.10.6
- 1.10.5
- 1.10.5-retag
- 1.10.4
- 1.10.3
- 1.10.2
- 1.10.1
- 1.10.0
- 1.9.1
- 1.9.0
- 1.9.0-rc2
- 1.9.0-rc1
- 1.8.3
- 1.8.2
- 1.8.1
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.7.0-rc1
- 1.6.0
- 1.5.1
- 1.5.0
Showing
16 changed files
with
434 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
core/src/main/java/org/testcontainers/containers/wait/WaitAllStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.testcontainers.containers.wait; | ||
|
||
import org.rnorth.ducttape.timeouts.Timeouts; | ||
import org.testcontainers.containers.GenericContainer; | ||
|
||
import java.time.Duration; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Wait strategy that waits for a number of other strategies to pass in series. | ||
*/ | ||
public class WaitAllStrategy implements WaitStrategy { | ||
|
||
private final List<WaitStrategy> strategies = new ArrayList<>(); | ||
private Duration timeout = Duration.ofSeconds(30); | ||
|
||
@Override | ||
public void waitUntilReady(GenericContainer container) { | ||
Timeouts.doWithTimeout((int) timeout.toMillis(), TimeUnit.MILLISECONDS, () -> { | ||
for (WaitStrategy strategy : strategies) { | ||
strategy.waitUntilReady(container); | ||
} | ||
}); | ||
} | ||
|
||
public WaitAllStrategy withStrategy(WaitStrategy strategy) { | ||
this.strategies.add(strategy); | ||
return this; | ||
} | ||
|
||
@Override | ||
public WaitStrategy withStartupTimeout(Duration startupTimeout) { | ||
this.timeout = startupTimeout; | ||
return this; | ||
} | ||
} |
Oops, something went wrong.