-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: apply test-http2-max-session-memory-leak from v12.x
Refs: #27914 Backport-PR-URL: #29124 PR-URL: #29122 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
073108c
commit cc28223
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const http2 = require('http2'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/27416. | ||
// Check that received data is accounted for correctly in the maxSessionMemory | ||
// mechanism. | ||
|
||
const bodyLength = 8192; | ||
const maxSessionMemory = 1; // 1 MB | ||
const requestCount = 1000; | ||
|
||
const server = http2.createServer({ maxSessionMemory }); | ||
server.on('stream', (stream) => { | ||
stream.respond(); | ||
stream.end(); | ||
}); | ||
|
||
server.listen(common.mustCall(() => { | ||
const client = http2.connect(`http://localhost:${server.address().port}`, { | ||
maxSessionMemory | ||
}); | ||
|
||
function request() { | ||
return new Promise((resolve, reject) => { | ||
const stream = client.request({ | ||
':method': 'POST', | ||
'content-length': bodyLength | ||
}); | ||
stream.on('error', reject); | ||
stream.on('response', resolve); | ||
stream.end('a'.repeat(bodyLength)); | ||
}); | ||
} | ||
|
||
(async () => { | ||
for (let i = 0; i < requestCount; i++) { | ||
await request(); | ||
} | ||
|
||
client.close(); | ||
server.close(); | ||
})().then(common.mustCall()); | ||
})); |