Skip to content

Commit ae2e0b9

Browse files
Fix flaky healthcheck timeout test (#930)
1 parent c7ea7ea commit ae2e0b9

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

packages/testcontainers/fixtures/docker-compose/docker-compose-with-healthcheck-with-start-period.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@ services:
66
ports:
77
- 8080
88
healthcheck:
9-
test: "curl -f http://localhost:8080/hello-world || exit 1"
10-
interval: 1s
11-
timeout: 1s
12-
retries: 1
13-
start_period: 10s
9+
test: "sleep 10"
10+
timeout: 10s

packages/testcontainers/src/docker-compose-environment/docker-compose-environment.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,16 @@ describe("DockerComposeEnvironment", { timeout: 180_000 }, () => {
135135
).rejects.toThrow(`Health check failed: unhealthy`);
136136
});
137137

138-
if (!process.env.CI_PODMAN) {
139-
it("should stop the container when the health check wait strategy times out", async () => {
140-
await expect(
141-
new DockerComposeEnvironment(fixtures, "docker-compose-with-healthcheck-with-start-period.yml")
142-
.withWaitStrategy(await composeContainerName("container"), Wait.forHealthCheck())
143-
.withStartupTimeout(0)
144-
.up()
145-
).rejects.toThrow(`Health check not healthy after 0ms`);
146-
147-
expect(await getRunningContainerNames()).not.toContain("container_1");
148-
});
149-
}
138+
it("should stop the container when the health check wait strategy times out", async () => {
139+
await expect(
140+
new DockerComposeEnvironment(fixtures, "docker-compose-with-healthcheck-with-start-period.yml")
141+
.withWaitStrategy(await composeContainerName("container"), Wait.forHealthCheck())
142+
.withStartupTimeout(0)
143+
.up()
144+
).rejects.toThrow(`Health check not healthy after 0ms`);
145+
146+
expect(await getRunningContainerNames()).not.toContain("container_1");
147+
});
150148

151149
it("should remove volumes when downing an environment", async () => {
152150
const environment = await new DockerComposeEnvironment(fixtures, "docker-compose-with-volume.yml").up();

packages/testcontainers/src/wait-strategies/health-check-wait-strategy.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe("HealthCheckWaitStrategy", { timeout: 180_000 }, () => {
6565
.withName(containerName)
6666
.withExposedPorts(8080)
6767
.withWaitStrategy(Wait.forHealthCheck())
68+
.withHealthCheck({ test: ["CMD-SHELL", "sleep 10"], timeout: 10_000 })
6869
.withStartupTimeout(0)
6970
.start()
7071
).rejects.toThrowError("Health check not healthy after 0ms");

0 commit comments

Comments
 (0)