diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/socket-back-pressure.js | |
parent | Initial commit. (diff) | |
download | node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.tar.xz node-undici-0b6210cd37b68b94252cb798598b12974a20e1c1.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/socket-back-pressure.js')
-rw-r--r-- | test/socket-back-pressure.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/socket-back-pressure.js b/test/socket-back-pressure.js new file mode 100644 index 0000000..9e774b3 --- /dev/null +++ b/test/socket-back-pressure.js @@ -0,0 +1,54 @@ +'use strict' + +const { Client } = require('..') +const { createServer } = require('http') +const { Readable } = require('stream') +const { test } = require('tap') + +test('socket back-pressure', (t) => { + t.plan(3) + + const server = createServer() + let bytesWritten = 0 + + const buf = Buffer.allocUnsafe(16384) + const src = new Readable({ + read () { + bytesWritten += buf.length + this.push(buf) + if (bytesWritten >= 1e6) { + this.push(null) + } + } + }) + + server.on('request', (req, res) => { + src.pipe(res) + }) + t.teardown(server.close.bind(server)) + + server.listen(0, () => { + const client = new Client(`http://localhost:${server.address().port}`, { + pipelining: 1 + }) + t.teardown(client.destroy.bind(client)) + + client.request({ path: '/', method: 'GET', opaque: 'asd' }, (err, data) => { + t.error(err) + data.body + .resume() + .once('data', () => { + data.body.pause() + // TODO: Try to avoid timeout. + setTimeout(() => { + t.ok(data.body._readableState.length < bytesWritten - data.body._readableState.highWaterMark) + src.push(null) + data.body.resume() + }, 1e3) + }) + .on('end', () => { + t.pass() + }) + }) + }) +}) |