-
-
Notifications
You must be signed in to change notification settings - Fork 252
Allow to use HealthCheck wait strategy by default #1096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
e743132
40fb443
7352220
f47af2e
b94ce11
e54c7bb
27f20fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import path from "path"; | ||
| import { HealthCheckWaitStrategy } from "../wait-strategies/health-check-wait-strategy"; | ||
| import { HostPortWaitStrategy } from "../wait-strategies/host-port-wait-strategy"; | ||
| import { Wait } from "../wait-strategies/wait"; | ||
| import { GenericContainer } from "./generic-container"; | ||
|
|
||
| const fixtures = path.resolve(__dirname, "..", "..", "fixtures", "docker"); | ||
|
|
||
| describe("GenericContainer wait strategy", { timeout: 180_000 }, () => { | ||
| it("should use Wait.forListeningPorts if healthcheck is not defined in DOCKERFILE", async () => { | ||
| await using container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14") | ||
| .withExposedPorts(8080) | ||
| .start(); | ||
| expect(container.getWaitStrategy()).toBeInstanceOf(HostPortWaitStrategy); | ||
| }); | ||
| it("should use Wait.forHealthCheck if withHealthCheck() explicitly called", async () => { | ||
| await using container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14") | ||
| .withExposedPorts(8080) | ||
| .withHealthCheck({ | ||
| test: ["CMD-SHELL", "echo 'started' && exit 0"], | ||
| }) | ||
| .start(); | ||
| expect(container.getWaitStrategy()).toBeInstanceOf(HealthCheckWaitStrategy); | ||
| }); | ||
| it("should use Wait.forHealthCheck if healthcheck is defined in DOCKERFILE", async () => { | ||
| const context = path.resolve(fixtures, "docker-with-health-check"); | ||
| const genericContainer = await GenericContainer.fromDockerfile(context).build(); | ||
| await using startedContainer = await genericContainer.start(); | ||
| expect(startedContainer.getWaitStrategy()).toBeInstanceOf(HealthCheckWaitStrategy); | ||
|
Check failure on line 29 in packages/testcontainers/src/generic-container/generic-container-wait-strategy.test.ts
|
||
| }); | ||
| it("should use same WaitStrategy if it's explicitly defined in withWaitStrategy() even if image defines healthcheck", async () => { | ||
| const context = path.resolve(fixtures, "docker-with-health-check"); | ||
| const genericContainer = await GenericContainer.fromDockerfile(context).build(); | ||
| await using container = await genericContainer | ||
| .withExposedPorts(8080) | ||
| .withWaitStrategy(Wait.forListeningPorts()) | ||
| .start(); | ||
| expect(container.getWaitStrategy()).toBeInstanceOf(HostPortWaitStrategy); | ||
| }); | ||
| it("should use same WaitStrategy if it's explicitly defined in withWaitStrategy() even if withHealthCheck() is called", async () => { | ||
| await using container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14") | ||
| .withExposedPorts(8080) | ||
| .withHealthCheck({ | ||
| test: ["CMD-SHELL", "echo 'started' && exit 0"], | ||
| }) | ||
| .withWaitStrategy(Wait.forListeningPorts()) | ||
| .start(); | ||
| expect(container.getWaitStrategy()).toBeInstanceOf(HostPortWaitStrategy); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { AbstractWaitStrategy } from "./wait-strategy"; | ||
|
|
||
| export class NullWaitStrategy extends AbstractWaitStrategy { | ||
| public override waitUntilReady(): Promise<void> { | ||
| return Promise.resolve(); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.