1'use strict'; 2 3const { mustCall, hasCrypto, skip } = require('../common'); 4if (!hasCrypto) 5 skip('missing crypto'); 6const assert = require('assert'); 7const { createServer, connect } = require('http2'); 8const { once } = require('events'); 9 10// This test ensures that `bufferSize` of Http2Session and Http2Stream work 11// as expected. 12{ 13 const kSockets = 2; 14 const kTimes = 10; 15 const kBufferSize = 30; 16 const server = createServer(); 17 18 let client; 19 20 const getStream = async () => { 21 const [ stream ] = await once(server, 'stream'); 22 stream.on('data', mustCall()); 23 stream.on('end', mustCall()); 24 stream.on('close', mustCall()); 25 return once(stream, 'close'); 26 }; 27 28 const promises = [...new Array(kSockets)].map(getStream); 29 Promise.all(promises).then(mustCall(() => { 30 client.close(); 31 server.close(); 32 })); 33 34 server.listen(0, mustCall(() => { 35 const authority = `http://localhost:${server.address().port}`; 36 client = connect(authority); 37 38 client.once('connect', mustCall()); 39 40 for (let j = 0; j < kSockets; j += 1) { 41 const stream = client.request({ ':method': 'POST' }); 42 stream.on('data', () => {}); 43 44 for (let i = 0; i < kTimes; i += 1) { 45 stream.write(Buffer.allocUnsafe(kBufferSize), mustCall()); 46 const expectedSocketBufferSize = kBufferSize * (i + 1); 47 assert.strictEqual(stream.bufferSize, expectedSocketBufferSize); 48 } 49 stream.end(); 50 stream.close(); 51 } 52 })); 53} 54