You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/features/advanced.md
+30Lines changed: 30 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,35 @@
1
1
# Advanced
2
2
3
+
## Timeout parameter of APIs
4
+
5
+
Testcontainers library provides a set of classes and functions, and some of them expect a parameter named `timeout`, `ms`, or similar to be passed from the caller. This parameters are of type `number`, and the unit of measurement for this parameters across all public APIs is the same: millisecond. For example:
6
+
7
+
```js
8
+
exportinterfaceTestContainer {
9
+
...
10
+
withStartupTimeout(ms: number): this; // timeout expected to be passed as milliseconds
11
+
}
12
+
```
13
+
14
+
The underlying docker APIs may expect different units for timeouts and intervals, and testcontainers library will do the needed conversion under the hood automatically. For example, consider the `stop` method of a container:
awaitcontainer.stop({ timeout:10_000 }); // testcontainers library expects the timeout to be passed as milliseconds
19
+
```
20
+
21
+
The Docker API [expects seconds](https://docs.docker.com/reference/api/engine/version/v1.48/#tag/Container/operation/ContainerStop) to be passed to this API call. The 10_000 ms value will be converted to seconds by testontainers library.
22
+
23
+
Keep in mind that conversion from ms to seconds uses truncation to integer, for example:
24
+
25
+
```
26
+
5000ms = 5s
27
+
3800ms = 3s
28
+
500ms = 0s
29
+
```
30
+
31
+
You may also pass a *negative* value to function parameters, but this may lead to unexpedted results.
32
+
3
33
## Container Runtime Client
4
34
5
35
Testcontainers configures an underlying container runtime to perform its tasks. This runtime works automatically with several providers like Docker, Podman, Colima, Rancher Desktop and Testcontainers Desktop. There are too many usage examples to list here, but here are some common examples:
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:
@@ -202,11 +202,11 @@ const container = await new GenericContainer("alpine")
202
202
.start();
203
203
```
204
204
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:
205
+
The composite wait strategy by default will respect each individual wait strategy's startup timeout. For example:
206
206
207
207
```javascript
208
-
constw1=Wait.forListeningPorts().withStartupTimeout(1000); //wait 1 second
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:
218
218
219
219
```javascript
220
-
constw1=Wait.forListeningPorts().withStartupTimeout(1000); //wait 1 second
220
+
constw1=Wait.forListeningPorts().withStartupTimeout(1000); // 1 second
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**.
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.
0 commit comments