Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions benchmarks/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,30 @@ const dispatcher = new Class(httpBaseOptions.url, {
...dest
})

setGlobalDispatcher(new Agent({
const globalDispatcher = new Agent({
pipelining,
connections,
connect: {
rejectUnauthorized: false
}
}))
})

setGlobalDispatcher(globalDispatcher)

async function cleanup () {
httpNoKeepAliveOptions.agent.destroy()
httpKeepAliveOptions.agent.destroy()
axiosAgent.destroy()
fetchAgent.destroy()
gotAgent.destroy()
requestAgent.destroy()
superagentAgent.destroy()

await Promise.allSettled([
dispatcher.destroy(),
globalDispatcher.destroy()
])
}

class SimpleRequest {
constructor (resolve) {
Expand Down Expand Up @@ -317,8 +334,16 @@ async function main () {
// https://github.com/ladjs/superagent/issues/1540#issue-561464561
superagent = _superagent.agent().use((req) => req.agent(superagentAgent))

// cronometro runs each benchmark in a worker, so attach cleanup to every
// test before the worker exits.
const tests = Object.fromEntries(
Object.entries(experiments).map(([name, test]) => {
return [name, { test, after: cleanup }]
})
)

cronometro(
experiments,
tests,
{
iterations,
errorThreshold,
Expand All @@ -330,7 +355,7 @@ async function main () {
}

printResults(results)
dispatcher.destroy()
cleanup()
}
)
}
Expand Down
Loading