test: optimize test-http2-large-file · nodejs/node@7ebd6bd (original) (raw)

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1 1 'use strict';
2 2
3 -// Test to ensure sending a large stream with a large initial window size works
3 +// Test sending a large stream with a large initial window size.
4 4 // See: https://github.com/nodejs/node/issues/19141
5 5
6 6 const common = require('../common');
@@ -18,14 +18,15 @@ server.on('stream', (stream) => {
18 18
19 19 server.listen(0, common.mustCall(() => {
20 20 let remaining = 1e8;
21 -const chunk = 1e6;
21 +const chunkLength = 1e6;
22 +const chunk = Buffer.alloc(chunkLength, 'a');
22 23 const client = http2.connect(`http://localhost:${server.address().port}\`,
23 24 { settings: { initialWindowSize: 6553500 } });
24 25 const request = client.request({ ':method': 'POST' });
25 26 function writeChunk() {
26 27 if (remaining > 0) {
27 -remaining -= chunk;
28 -request.write(Buffer.alloc(chunk, 'a'), writeChunk);
28 +remaining -= chunkLength;
29 +request.write(chunk, writeChunk);
29 30 } else {
30 31 request.end();
31 32 }