Skip to content

Commit 38d80f0

Browse files
wait-strategies touch ups
1 parent 9ff3d83 commit 38d80f0

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

docs/features/wait-strategies.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,32 @@ Wait until the container's health check is successful:
7070
```js
7171
const { GenericContainer, Wait } = require("testcontainers");
7272

73-
const container = await new GenericContainer("alpine").withWaitStrategy(Wait.forHealthCheck()).start();
73+
const container = await new GenericContainer("alpine")
74+
.withWaitStrategy(Wait.forHealthCheck())
75+
.start();
7476
```
7577

76-
Define your own health check:
78+
Define your own health check. Note that time units are in seconds:
7779

7880
```js
7981
const { GenericContainer, Wait } = require("testcontainers");
8082

8183
const container = await new GenericContainer("alpine")
8284
.withHealthCheck({
8385
test: ["CMD-SHELL", "curl -f http://localhost || exit 1"],
84-
interval: 1000, // 1 second
85-
timeout: 3000, // 3 seconds
86+
interval: 1000,
87+
timeout: 3000,
8688
retries: 5,
87-
startPeriod: 1000, // 1 second
89+
startPeriod: 1000,
8890
})
8991
.withWaitStrategy(Wait.forHealthCheck())
9092
.start();
9193
```
9294

9395
Note that `interval`, `timeout`, `retries` and `startPeriod` are optional as they are inherited from the image or parent image if omitted.
9496

97+
---
98+
9599
To execute the test with a shell use the form `["CMD-SHELL", "command"]`:
96100

97101
```js
@@ -106,12 +110,14 @@ To execute the test without a shell, use the form: `["CMD", "command", "arg1", "
106110

107111
## HTTP
108112

109-
Wait for an HTTP request to satisfy a condition. By default, it will wait for a 200 response:
113+
Wait for a HTTP request to satisfy a condition. By default, it will wait for a 200 response:
110114

111115
```js
112116
const { GenericContainer, Wait } = require("testcontainers");
113117

114-
const container = await new GenericContainer("redis").withWaitStrategy(Wait.forHttp("/health", 8080)).start();
118+
const container = await new GenericContainer("redis")
119+
.withWaitStrategy(Wait.forHttp("/health", 8080))
120+
.start();
115121
```
116122

117123
Stop waiting after container exited if waiting for container restart not needed.
@@ -131,7 +137,7 @@ const container = await new GenericContainer("redis")
131137
.forStatusCode(201))
132138

133139
.withWaitStrategy(Wait.forHttp("/health", 8080)
134-
.forStatusCodeMatching(statusCode => statusCode === 201))
140+
.forStatusCodeMatching(statusCode => `${statusCode}`.startsWith("2")))
135141
```
136142

137143
### For response body

0 commit comments

Comments
 (0)