11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ciconst http2 = require('http2'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// Regression test for https://github.com/nodejs/node/issues/27416. 81cb0ef41Sopenharmony_ci// Check that received data is accounted for correctly in the maxSessionMemory 91cb0ef41Sopenharmony_ci// mechanism. 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst bodyLength = 8192; 121cb0ef41Sopenharmony_ciconst maxSessionMemory = 1; // 1 MiB 131cb0ef41Sopenharmony_ciconst requestCount = 1000; 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst server = http2.createServer({ maxSessionMemory }); 161cb0ef41Sopenharmony_ciserver.on('stream', (stream) => { 171cb0ef41Sopenharmony_ci stream.respond(); 181cb0ef41Sopenharmony_ci stream.end(); 191cb0ef41Sopenharmony_ci}); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciserver.listen(common.mustCall(() => { 221cb0ef41Sopenharmony_ci const client = http2.connect(`http://localhost:${server.address().port}`, { 231cb0ef41Sopenharmony_ci maxSessionMemory 241cb0ef41Sopenharmony_ci }); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci function request() { 271cb0ef41Sopenharmony_ci return new Promise((resolve, reject) => { 281cb0ef41Sopenharmony_ci const stream = client.request({ 291cb0ef41Sopenharmony_ci ':method': 'POST', 301cb0ef41Sopenharmony_ci 'content-length': bodyLength 311cb0ef41Sopenharmony_ci }); 321cb0ef41Sopenharmony_ci stream.on('error', reject); 331cb0ef41Sopenharmony_ci stream.on('response', resolve); 341cb0ef41Sopenharmony_ci stream.end('a'.repeat(bodyLength)); 351cb0ef41Sopenharmony_ci }); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci (async () => { 391cb0ef41Sopenharmony_ci for (let i = 0; i < requestCount; i++) { 401cb0ef41Sopenharmony_ci await request(); 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci client.close(); 441cb0ef41Sopenharmony_ci server.close(); 451cb0ef41Sopenharmony_ci })().then(common.mustCall()); 461cb0ef41Sopenharmony_ci})); 47