|
48 | 48 |
|
49 | 49 | public class GenericContainerTest { |
50 | 50 |
|
51 | | - @Test |
52 | | - public void testStartupTimeoutWithAttemptsNotLeakingContainers() { |
53 | | - try ( |
54 | | - GenericContainer<?> container = new GenericContainer<>(TestImages.TINY_IMAGE) |
55 | | - .withStartupAttempts(3) |
56 | | - .waitingFor( |
57 | | - Wait.forLogMessage("this text does not exist in logs", 1).withStartupTimeout(Duration.ofMillis(1)) |
58 | | - ) |
59 | | - .withCommand("tail", "-f", "/dev/null"); |
60 | | - ) { |
61 | | - assertThatThrownBy(container::start).hasStackTraceContaining("Retry limit hit with exception"); |
62 | | - } |
63 | | - assertThat(reportLeakedContainers()).isEmpty(); |
64 | | - } |
65 | | - |
66 | 51 | @Test |
67 | 52 | public void shouldReportOOMAfterWait() { |
68 | 53 | Info info = DockerClientFactory.instance().client().infoCmd().exec(); |
@@ -294,16 +279,33 @@ public void shouldRespectWaitStrategy() { |
294 | 279 | } |
295 | 280 | } |
296 | 281 |
|
| 282 | + @Test |
| 283 | + public void testStartupAttemptsDoesNotLeaveContainersRunningWhenWrongWaitStrategyIsUsed() { |
| 284 | + try ( |
| 285 | + GenericContainer<?> container = new GenericContainer<>(TestImages.TINY_IMAGE) |
| 286 | + .withLabel("waitstrategy", "wrong") |
| 287 | + .withStartupAttempts(3) |
| 288 | + .waitingFor( |
| 289 | + Wait.forLogMessage("this text does not exist in logs", 1).withStartupTimeout(Duration.ofMillis(1)) |
| 290 | + ) |
| 291 | + .withCommand("tail", "-f", "/dev/null"); |
| 292 | + ) { |
| 293 | + assertThatThrownBy(container::start).hasStackTraceContaining("Retry limit hit with exception"); |
| 294 | + } |
| 295 | + assertThat(reportLeakedContainers()).isEmpty(); |
| 296 | + } |
| 297 | + |
297 | 298 | private static Optional<String> reportLeakedContainers() { |
298 | 299 | @SuppressWarnings("resource") // Throws when close is attempted, as this is a global instance. |
299 | 300 | DockerClient dockerClient = DockerClientFactory.lazyClient(); |
300 | 301 |
|
301 | 302 | List<Container> containers = dockerClient |
302 | 303 | .listContainersCmd() |
| 304 | + .withAncestorFilter(Collections.singletonList("alpine:3.17")) |
303 | 305 | .withLabelFilter( |
304 | | - Collections.singletonMap( |
305 | | - DockerClientFactory.TESTCONTAINERS_SESSION_ID_LABEL, |
306 | | - DockerClientFactory.SESSION_ID |
| 306 | + Arrays.asList( |
| 307 | + DockerClientFactory.TESTCONTAINERS_SESSION_ID_LABEL + "=" + DockerClientFactory.SESSION_ID, |
| 308 | + "waitstrategy=wrong" |
307 | 309 | ) |
308 | 310 | ) |
309 | 311 | // ignore status "exited" - for example, failed containers after using `withStartupAttempts()` |
|
0 commit comments