• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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```
21