Skip to content

Commit f4ca0be

Browse files
authored
fix(benchmark): set body correctly (#2918)
* fix(benchmark): set body correctly * fix: `undici.pipeline` set body correctly * fix: maybe fix `undici.pipeline` * fixup
1 parent b54facd commit f4ca0be

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

benchmarks/post-benchmark.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
const http = require('node:http')
44
const os = require('node:os')
55
const path = require('node:path')
6-
const { Writable } = require('node:stream')
6+
const { Writable, Readable, pipeline } = require('node:stream')
77
const { isMainThread } = require('node:worker_threads')
8-
98
const { Pool, Client, fetch, Agent, setGlobalDispatcher } = require('..')
109

1110
let nodeFetch
@@ -230,19 +229,28 @@ const experiments = {
230229
},
231230
'undici - pipeline' () {
232231
return makeParallelRequests(resolve => {
233-
dispatcher
234-
.pipeline(undiciOptions, data => {
232+
pipeline(
233+
new Readable({
234+
read () {
235+
this.push(data)
236+
this.push(null)
237+
}
238+
}),
239+
dispatcher.pipeline(undiciOptions, data => {
235240
return data.body
236-
})
237-
.end()
238-
.pipe(
239-
new Writable({
240-
write (chunk, encoding, callback) {
241-
callback()
242-
}
243-
})
244-
)
245-
.on('finish', resolve)
241+
}),
242+
new Writable({
243+
write (chunk, encoding, callback) {
244+
callback()
245+
}
246+
}),
247+
(err) => {
248+
if (err != null) {
249+
console.log(err)
250+
}
251+
resolve()
252+
}
253+
)
246254
})
247255
},
248256
'undici - request' () {
@@ -357,7 +365,7 @@ if (process.env.PORT) {
357365
method: 'POST',
358366
headers,
359367
agent: requestAgent,
360-
data
368+
body: data
361369
}
362370
experiments.request = () => {
363371
return makeParallelRequests(resolve => {

0 commit comments

Comments
 (0)