main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
648 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | # Writing tests
|
---|
| 2 |
|
---|
| 3 | Undici is tuned for a production use case and its default will keep
|
---|
| 4 | a socket open for a few seconds after an HTTP request is completed to
|
---|
| 5 | remove the overhead of opening up a new socket. These settings that makes
|
---|
| 6 | Undici shine in production are not a good fit for using Undici in automated
|
---|
| 7 | tests, as it will result in longer execution times.
|
---|
| 8 |
|
---|
| 9 | The following are good defaults that will keep the socket open for only 10ms:
|
---|
| 10 |
|
---|
| 11 | ```js
|
---|
| 12 | import { request, setGlobalDispatcher, Agent } from 'undici'
|
---|
| 13 |
|
---|
| 14 | const agent = new Agent({
|
---|
| 15 | keepAliveTimeout: 10, // milliseconds
|
---|
| 16 | keepAliveMaxTimeout: 10 // milliseconds
|
---|
| 17 | })
|
---|
| 18 |
|
---|
| 19 | setGlobalDispatcher(agent)
|
---|
| 20 | ```
|
---|
Note:
See
TracBrowser
for help on using the repository browser.