test: optimize test-http2-large-file
Optimize test-http2-large-file so it only allocates a single buffer. PR-URL: https://github.com/nodejs/node/pull/26737 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Adrian Estrada <edsadr@gmail.com>
This commit is contained in:
parent
42dbaed460
commit
ba1c5fffaf
@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Test to ensure sending a large stream with a large initial window size works
|
// Test sending a large stream with a large initial window size.
|
||||||
// See: https://github.com/nodejs/node/issues/19141
|
// See: https://github.com/nodejs/node/issues/19141
|
||||||
|
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
@ -18,14 +18,15 @@ server.on('stream', (stream) => {
|
|||||||
|
|
||||||
server.listen(0, common.mustCall(() => {
|
server.listen(0, common.mustCall(() => {
|
||||||
let remaining = 1e8;
|
let remaining = 1e8;
|
||||||
const chunk = 1e6;
|
const chunkLength = 1e6;
|
||||||
|
const chunk = Buffer.alloc(chunkLength, 'a');
|
||||||
const client = http2.connect(`http://localhost:${server.address().port}`,
|
const client = http2.connect(`http://localhost:${server.address().port}`,
|
||||||
{ settings: { initialWindowSize: 6553500 } });
|
{ settings: { initialWindowSize: 6553500 } });
|
||||||
const request = client.request({ ':method': 'POST' });
|
const request = client.request({ ':method': 'POST' });
|
||||||
function writeChunk() {
|
function writeChunk() {
|
||||||
if (remaining > 0) {
|
if (remaining > 0) {
|
||||||
remaining -= chunk;
|
remaining -= chunkLength;
|
||||||
request.write(Buffer.alloc(chunk, 'a'), writeChunk);
|
request.write(chunk, writeChunk);
|
||||||
} else {
|
} else {
|
||||||
request.end();
|
request.end();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user