Skip to content

Commit 3a11d41

Browse files
authored
Docs: clarified timeout unit in different places (#958)
1 parent aa95e75 commit 3a11d41

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

docs/features/compose.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
140140
await environment.down();
141141
```
142142

143-
If you need to wait for the environment to be downed, you can provide a timeout:
143+
If you need to wait for the environment to be downed, you can provide a timeout. The unit of timeout here is **second**:
144144

145145
```javascript
146146
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile).up();
147-
await environment.down({ timeout: 10000 }); // ms
147+
await environment.down({ timeout: 10 }); // timeout after 10 seconds
148148
```
149149

150150
Volumes created by the environment are removed when stopped. This is configurable:

docs/features/containers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ const container = await new GenericContainer("alpine").start();
334334
await container.stop();
335335
```
336336

337-
If you need to wait for the container to be stopped, you can provide a timeout:
337+
If you need to wait for the container to be stopped, you can provide a timeout. The unit of timeout option here is **second**:
338338

339339
```javascript
340340
const container = await new GenericContainer("alpine").start();
341-
await container.stop({ timeout: 10000 }); // ms
341+
await container.stop({ timeout: 10 }); // 10 seconds
342342
```
343343

344344
You can disable automatic removal of the container, which is useful for debugging, or if for example you want to copy content from the container once it has stopped:

docs/features/wait-strategies.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Wait Strategies
22

3-
Note that the startup timeout of all wait strategies is configurable:
3+
Note that the startup timeout of all wait strategies is configurable. The unit of timeout of wait strategies is **millisecond**:
44

55
```javascript
66
const { GenericContainer } = require("testcontainers");
77

88
const container = await new GenericContainer("alpine")
9-
.withStartupTimeout(120000) // wait 120s
9+
.withStartupTimeout(120000) // wait 120 seconds
1010
.start();
1111
```
1212

@@ -73,7 +73,7 @@ const { GenericContainer, Wait } = require("testcontainers");
7373
const container = await new GenericContainer("alpine").withWaitStrategy(Wait.forHealthCheck()).start();
7474
```
7575

76-
Define your own health check:
76+
Define your own health check. The unit of timeouts and intervals here is **millisecond**:
7777

7878
```javascript
7979
const { GenericContainer, Wait } = require("testcontainers");
@@ -148,7 +148,7 @@ const container = await new GenericContainer("redis")
148148
.withMethod("POST")
149149
.withHeaders({ X_CUSTOM_VALUE: "custom" })
150150
.withBasicCredentials("username", "password")
151-
.withReadTimeout(10000))
151+
.withReadTimeout(10000)) // timeout after 10 seconds
152152
```
153153

154154
### Use TLS
@@ -202,11 +202,11 @@ const container = await new GenericContainer("alpine")
202202
.start();
203203
```
204204

205-
The composite wait strategy by default will respect each individual wait strategy's startup timeout. For example:
205+
The composite wait strategy by default will respect each individual wait strategy's startup timeout. The unit of timeouts here is **millisecond**. For example:
206206

207207
```javascript
208-
const w1 = Wait.forListeningPorts().withStartupTimeout(1000);
209-
const w2 = Wait.forLogMessage("READY").withStartupTimeout(2000);
208+
const w1 = Wait.forListeningPorts().withStartupTimeout(1000); // wait 1 second
209+
const w2 = Wait.forLogMessage("READY").withStartupTimeout(2000); // wait 2 seconds
210210

211211
const composite = Wait.forAll([w1, w2]);
212212

@@ -217,21 +217,21 @@ expect(w2.getStartupTimeout()).toBe(2000);
217217
The startup timeout of inner wait strategies that have not defined their own startup timeout can be set by setting the startup timeout on the composite:
218218

219219
```javascript
220-
const w1 = Wait.forListeningPorts().withStartupTimeout(1000);
220+
const w1 = Wait.forListeningPorts().withStartupTimeout(1000); // wait 1 second
221221
const w2 = Wait.forLogMessage("READY");
222222

223-
const composite = Wait.forAll([w1, w2]).withStartupTimeout(2000);
223+
const composite = Wait.forAll([w1, w2]).withStartupTimeout(2000); // wait 2 seconds
224224

225225
expect(w1.getStartupTimeout()).toBe(1000);
226226
expect(w2.getStartupTimeout()).toBe(2000);
227227
```
228228

229-
The startup timeout of all wait strategies can be controlled by setting a deadline on the composite. In this case, the composite will throw unless all inner wait strategies have resolved before the deadline.
229+
The startup timeout of all wait strategies can be controlled by setting a deadline on the composite. In this case, the composite will throw unless all inner wait strategies have resolved before the deadline. The unit of deadline timeout is **millisecond**.
230230

231231
```javascript
232232
const w1 = Wait.forListeningPorts();
233233
const w2 = Wait.forLogMessage("READY");
234-
const composite = Wait.forAll([w1, w2]).withDeadline(2000);
234+
const composite = Wait.forAll([w1, w2]).withDeadline(2000); // wait 2 seconds
235235
```
236236

237237
## Other startup strategies
@@ -248,7 +248,7 @@ const {
248248

249249
class ReadyAfterDelayWaitStrategy extends StartupCheckStrategy {
250250
public checkStartupState(dockerClient: Dockerode, containerId: string): Promise<StartupStatus> {
251-
return new Promise((resolve) => setTimeout(() => resolve("SUCCESS"), 3000));
251+
return new Promise((resolve) => setTimeout(() => resolve("SUCCESS"), 3000)); // after 3 seconds
252252
}
253253
}
254254

0 commit comments

Comments
 (0)