-
Notifications
You must be signed in to change notification settings - Fork 572
/
Copy pathclient-write-max-listeners.js
56 lines (45 loc) · 1.25 KB
/
client-write-max-listeners.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
const { tspl } = require('@matteo.collina/tspl')
const { test, after } = require('node:test')
const { once } = require('node:events')
const { Client } = require('..')
const { createServer } = require('node:http')
const { Readable } = require('node:stream')
test('socket close listener does not leak', async (t) => {
t = tspl(t, { plan: 32 })
const server = createServer()
server.on('request', (req, res) => {
res.end('hello')
})
after(() => server.close())
const makeBody = () => {
return new Readable({
read () {
process.nextTick(() => {
this.push(null)
})
}
})
}
const onRequest = (err, data) => {
t.ifError(err)
data.body.on('end', () => t.ok(true, 'pass')).resume()
}
function onWarning (warning) {
if (!/ExperimentalWarning/.test(warning)) {
t.fail()
}
}
process.on('warning', onWarning)
after(() => {
process.removeListener('warning', onWarning)
})
server.listen(0)
await once(server, 'listening')
const client = new Client(`http://localhost:${server.address().port}`)
after(() => client.destroy())
for (let n = 0; n < 16; ++n) {
client.request({ path: '/', method: 'GET', body: makeBody() }, onRequest)
}
await t.completed
})