Urara-Blog/node_modules/.pnpm-store/v3/files/dc/269c132dcd8940441872feb4422a0a3960815ccd3614038096be9a92ddec68b6e7806a2c3b953ada2084604e81bc30b43ba98f0c5b407dcdfa465a3b0a1adc
2022-08-14 01:14:53 +08:00

20 lines
648 B
Text

# Writing tests
Undici is tuned for a production use case and its default will keep
a socket open for a few seconds after an HTTP request is completed to
remove the overhead of opening up a new socket. These settings that makes
Undici shine in production are not a good fit for using Undici in automated
tests, as it will result in longer execution times.
The following are good defaults that will keep the socket open for only 10ms:
```js
import { request, setGlobalDispatcher, Agent } from 'undici'
const agent = new Agent({
keepAliveTimeout: 10, // milliseconds
keepAliveMaxTimeout: 10 // milliseconds
})
setGlobalDispatcher(agent)
```