package-rebuilds/pkgs/node-undici/node-undici-5.28.4+dfsg1+~cs23.12.11/test/request-timeout2.js
Fabian Grünbichler afee63929c add node-undici for libgit2 1.8.1
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2024-09-10 11:23:24 +02:00

49 lines
1.0 KiB
JavaScript

'use strict'
const { test } = require('tap')
const { Client } = require('..')
const { createServer } = require('http')
const { Readable } = require('stream')
test('request timeout with slow readable body', (t) => {
t.plan(1)
const server = createServer(async (req, res) => {
let str = ''
for await (const x of req) {
str += x
}
res.end(str)
})
t.teardown(server.close.bind(server))
server.listen(0, () => {
const client = new Client(`http://localhost:${server.address().port}`, { headersTimeout: 50 })
t.teardown(client.close.bind(client))
const body = new Readable({
read () {
if (this._reading) {
return
}
this._reading = true
this.push('asd')
setTimeout(() => {
this.push('asd')
this.push(null)
}, 2e3)
}
})
client.request({
path: '/',
method: 'POST',
headersTimeout: 1e3,
body
}, async (err, response) => {
t.error(err)
await response.body.dump()
})
})
})