Skip to content

Commit 075173a

Browse files
Add support for custom health checks in CockroachDbContainer
1 parent 55bb9b9 commit 075173a

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

packages/modules/cockroachdb/src/cockroachdb-container.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,15 @@ describe("CockroachDbContainer", () => {
101101
await client.end();
102102
await container.stop();
103103
});
104+
105+
it("should allow custom healthcheck", async () => {
106+
const container = new CockroachDbContainer().withHealthCheck({
107+
test: ["CMD-SHELL", "exit 1"],
108+
interval: 100,
109+
retries: 0,
110+
timeout: 0,
111+
});
112+
113+
await expect(() => container.start()).rejects.toThrow();
114+
});
104115
});

packages/modules/cockroachdb/src/cockroachdb-container.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ export class CockroachDbContainer extends GenericContainer {
99

1010
constructor(image = "cockroachdb/cockroach:v24.3.5") {
1111
super(image);
12-
this.withExposedPorts(COCKROACH_PORT, COCKROACH_HTTP_PORT).withCommand([
13-
"start-single-node",
14-
"--insecure",
15-
`--http-addr=0.0.0.0:${COCKROACH_HTTP_PORT}`,
16-
]);
12+
this.withExposedPorts(COCKROACH_PORT, COCKROACH_HTTP_PORT)
13+
.withCommand(["start-single-node", "--insecure", `--http-addr=0.0.0.0:${COCKROACH_HTTP_PORT}`])
14+
.withWaitStrategy(Wait.forHealthCheck());
1715
}
1816

1917
public withDatabase(database: string): this {
@@ -31,13 +29,14 @@ export class CockroachDbContainer extends GenericContainer {
3129
COCKROACH_DATABASE: this.database,
3230
COCKROACH_USER: this.username,
3331
});
34-
this.withHealthCheck({
35-
test: ["CMD-SHELL", `cockroach sql --insecure -u ${this.username} -d ${this.database} -e "SELECT 1;"`],
36-
interval: 250,
37-
timeout: 1000,
38-
retries: 1000,
39-
});
40-
this.withWaitStrategy(Wait.forHealthCheck());
32+
if (!this.healthCheck) {
33+
this.withHealthCheck({
34+
test: ["CMD-SHELL", `cockroach sql --insecure -u ${this.username} -d ${this.database} -e "SELECT 1;"`],
35+
interval: 250,
36+
timeout: 1000,
37+
retries: 1000,
38+
});
39+
}
4140
return new StartedCockroachDbContainer(await super.start(), this.database, this.username);
4241
}
4342
}

0 commit comments

Comments
 (0)