Skip to content

Commit c537cef

Browse files
committed
Polish
1 parent 902cb03 commit c537cef

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

core/src/test/java/org/testcontainers/containers/GenericContainerTest.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,6 @@
4848

4949
public class GenericContainerTest {
5050

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-
6651
@Test
6752
public void shouldReportOOMAfterWait() {
6853
Info info = DockerClientFactory.instance().client().infoCmd().exec();
@@ -294,16 +279,33 @@ public void shouldRespectWaitStrategy() {
294279
}
295280
}
296281

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+
297298
private static Optional<String> reportLeakedContainers() {
298299
@SuppressWarnings("resource") // Throws when close is attempted, as this is a global instance.
299300
DockerClient dockerClient = DockerClientFactory.lazyClient();
300301

301302
List<Container> containers = dockerClient
302303
.listContainersCmd()
304+
.withAncestorFilter(Collections.singletonList("alpine:3.17"))
303305
.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"
307309
)
308310
)
309311
// ignore status "exited" - for example, failed containers after using `withStartupAttempts()`

0 commit comments

Comments
 (0)