source: node_modules/undici/docs/best-practices/writing-tests.md@ d24f17c

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
Line 
1# Writing tests
2
3Undici is tuned for a production use case and its default will keep
4a socket open for a few seconds after an HTTP request is completed to
5remove the overhead of opening up a new socket. These settings that makes
6Undici shine in production are not a good fit for using Undici in automated
7tests, as it will result in longer execution times.
8
9The following are good defaults that will keep the socket open for only 10ms:
10
11```js
12import { request, setGlobalDispatcher, Agent } from 'undici'
13
14const agent = new Agent({
15 keepAliveTimeout: 10, // milliseconds
16 keepAliveMaxTimeout: 10 // milliseconds
17})
18
19setGlobalDispatcher(agent)
20```
Note: See TracBrowser for help on using the repository browser.