Skip to content

Commit b1da2db

Browse files
Podman emits events for starting
1 parent af68ee2 commit b1da2db

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/testcontainers/fixtures/docker-compose/docker-compose-with-healthcheck-unhealthy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ services:
77
- 8080
88
healthcheck:
99
test: "curl -f http://localhost:8081/hello-world || exit 1"
10-
interval: 1s
1110
timeout: 3s
12-
retries: 10
11+
interval: 1s
12+
retries: 0

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export class HealthCheckWaitStrategy extends AbstractWaitStrategy {
1818
reject(new Error(message));
1919
}, this.startupTimeout);
2020

21+
const onTerminalState = () => {
22+
clearTimeout(timeout);
23+
containerEvents.destroy();
24+
log.debug(`Health check wait strategy complete`, { containerId: container.id });
25+
};
26+
2127
containerEvents.on("data", (data) => {
2228
const parsedData = JSON.parse(data);
2329

@@ -28,15 +34,13 @@ export class HealthCheckWaitStrategy extends AbstractWaitStrategy {
2834

2935
if (status === "healthy") {
3036
resolve();
31-
} else {
37+
onTerminalState();
38+
} else if (status === "unhealthy") {
3239
const message = `Health check failed: ${status}`;
3340
log.error(message, { containerId: container.id });
3441
reject(new Error(message));
42+
onTerminalState();
3543
}
36-
37-
clearTimeout(timeout);
38-
containerEvents.destroy();
39-
log.debug(`Health check wait strategy complete`, { containerId: container.id });
4044
});
4145
});
4246
}

0 commit comments

Comments
 (0)