Skip to content

Commit

Permalink
fix(benchmark): set body correctly (#2918)
Browse files Browse the repository at this point in the history
* fix(benchmark): set body correctly

* fix: `undici.pipeline` set body correctly

* fix: maybe fix `undici.pipeline`

* fixup
  • Loading branch information
tsctx committed Mar 4, 2024
1 parent b54facd commit f4ca0be
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions benchmarks/post-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
const http = require('node:http')
const os = require('node:os')
const path = require('node:path')
const { Writable } = require('node:stream')
const { Writable, Readable, pipeline } = require('node:stream')
const { isMainThread } = require('node:worker_threads')

const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..')

let nodeFetch
Expand Down Expand Up @@ -230,19 +229,28 @@ const experiments = {
},
'undici - pipeline' () {
return makeParallelRequests(resolve => {
dispatcher
.pipeline(undiciOptions, data => {
pipeline(
new Readable({
read () {
this.push(data)
this.push(null)
}
}),
dispatcher.pipeline(undiciOptions, data => {
return data.body
})
.end()
.pipe(
new Writable({
write (chunk, encoding, callback) {
callback()
}
})
)
.on('finish', resolve)
}),
new Writable({
write (chunk, encoding, callback) {
callback()
}
}),
(err) => {
if (err != null) {
console.log(err)
}
resolve()
}
)
})
},
'undici - request' () {
Expand Down Expand Up @@ -357,7 +365,7 @@ if (process.env.PORT) {
method: 'POST',
headers,
agent: requestAgent,
data
body: data
}
experiments.request = () => {
return makeParallelRequests(resolve => {
Expand Down

0 comments on commit f4ca0be

Please sign in to comment.