Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/features/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
.up();
```

### With a default wait strategy

By default Testcontainers uses the "listening ports" wait strategy for all containers. If you'd like to override
the default wait strategy for all services, you can do so:

```javascript
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
.withDefaultWaitStrategy(Wait.forHealthCheck())
.up();
```

### With a pull policy

Testcontainers will automatically pull an image if it doesn't exist. This is configurable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ describe("DockerComposeEnvironment", { timeout: 180_000 }, () => {
await startedEnvironment.down();
});

it("should support default wait strategy", async () => {
const startedEnvironment = await new DockerComposeEnvironment(fixtures, "docker-compose-with-healthcheck.yml")
.withDefaultWaitStrategy(Wait.forHealthCheck())
.up();

await checkEnvironmentContainerIsHealthy(startedEnvironment, await composeContainerName("container"));

await startedEnvironment.down();
});

it("should support log message wait strategy", async () => {
const startedEnvironment = await new DockerComposeEnvironment(fixtures, "docker-compose.yml")
.withWaitStrategy(await composeContainerName("container"), Wait.forLogMessage("Listening on port 8080"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class DockerComposeEnvironment {
private profiles: string[] = [];
private environment: Environment = {};
private pullPolicy: ImagePullPolicy = PullPolicy.defaultPolicy();
private defaultWaitStrategy: WaitStrategy = Wait.forListeningPorts();
private waitStrategy: { [containerName: string]: WaitStrategy } = {};
private startupTimeout?: number;

Expand Down Expand Up @@ -63,6 +64,11 @@ export class DockerComposeEnvironment {
return this;
}

public withDefaultWaitStrategy(waitStrategy: WaitStrategy): this {
this.defaultWaitStrategy = waitStrategy;
return this;
}

public withWaitStrategy(containerName: string, waitStrategy: WaitStrategy): this {
this.waitStrategy[containerName] = waitStrategy;
return this;
Expand Down Expand Up @@ -140,7 +146,7 @@ export class DockerComposeEnvironment {
const boundPorts = BoundPorts.fromInspectResult(client.info.containerRuntime.hostIps, mappedInspectResult);
const waitStrategy = this.waitStrategy[containerName]
? this.waitStrategy[containerName]
: Wait.forListeningPorts();
: this.defaultWaitStrategy;
if (this.startupTimeout !== undefined) {
waitStrategy.withStartupTimeout(this.startupTimeout);
}
Expand Down
Loading