11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Test sending a large stream with a large initial window size.
41cb0ef41Sopenharmony_ci// See: https://github.com/nodejs/node/issues/19141
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst common = require('../common');
71cb0ef41Sopenharmony_ciif (!common.hasCrypto)
81cb0ef41Sopenharmony_ci  common.skip('missing crypto');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst http2 = require('http2');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciconst server = http2.createServer({ settings: { initialWindowSize: 6553500 } });
131cb0ef41Sopenharmony_ciserver.on('stream', (stream) => {
141cb0ef41Sopenharmony_ci  stream.resume();
151cb0ef41Sopenharmony_ci  stream.respond();
161cb0ef41Sopenharmony_ci  stream.end('ok');
171cb0ef41Sopenharmony_ci});
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => {
201cb0ef41Sopenharmony_ci  let remaining = 1e8;
211cb0ef41Sopenharmony_ci  const chunkLength = 1e6;
221cb0ef41Sopenharmony_ci  const chunk = Buffer.alloc(chunkLength, 'a');
231cb0ef41Sopenharmony_ci  const client = http2.connect(`http://localhost:${server.address().port}`,
241cb0ef41Sopenharmony_ci                               { settings: { initialWindowSize: 6553500 } });
251cb0ef41Sopenharmony_ci  const request = client.request({ ':method': 'POST' });
261cb0ef41Sopenharmony_ci  function writeChunk() {
271cb0ef41Sopenharmony_ci    if (remaining > 0) {
281cb0ef41Sopenharmony_ci      remaining -= chunkLength;
291cb0ef41Sopenharmony_ci      request.write(chunk, writeChunk);
301cb0ef41Sopenharmony_ci    } else {
311cb0ef41Sopenharmony_ci      request.end();
321cb0ef41Sopenharmony_ci    }
331cb0ef41Sopenharmony_ci  }
341cb0ef41Sopenharmony_ci  writeChunk();
351cb0ef41Sopenharmony_ci  request.on('close', common.mustCall(() => {
361cb0ef41Sopenharmony_ci    client.close();
371cb0ef41Sopenharmony_ci    server.close();
381cb0ef41Sopenharmony_ci  }));
391cb0ef41Sopenharmony_ci  request.resume();
401cb0ef41Sopenharmony_ci}));
41