Skip to content

Commit

Permalink
test: improve reliability of http2-session-timeout
Browse files Browse the repository at this point in the history
Check actual expired time rather than relying on a number of calls to
setTimeout() in test-http2-session-timeout more robust.

PR-URL: nodejs#20692
Fixes: nodejs#20628
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
Trott authored and kjin committed Oct 16, 2018
1 parent 11f194f commit 9cf40c5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/sequential/test-http2-session-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const h2 = require('http2');

const serverTimeout = common.platformTimeout(200);
const callTimeout = common.platformTimeout(20);
const minRuns = Math.ceil(serverTimeout / callTimeout) * 2;
const mustNotCall = common.mustNotCall();

const server = h2.createServer();
Expand All @@ -21,9 +20,10 @@ server.listen(0, common.mustCall(() => {

const url = `http://localhost:${port}`;
const client = h2.connect(url);
makeReq(minRuns);
const startTime = process.hrtime();
makeReq();

function makeReq(attempts) {
function makeReq() {
const request = client.request({
':path': '/foobar',
':method': 'GET',
Expand All @@ -34,12 +34,14 @@ server.listen(0, common.mustCall(() => {
request.end();

request.on('end', () => {
if (attempts) {
setTimeout(() => makeReq(attempts - 1), callTimeout);
const diff = process.hrtime(startTime);
const milliseconds = (diff[0] * 1e3 + diff[1] / 1e6);
if (milliseconds < serverTimeout * 2) {
setTimeout(makeReq, callTimeout);
} else {
server.removeListener('timeout', mustNotCall);
client.close();
server.close();
client.close();
}
});
}
Expand Down

0 comments on commit 9cf40c5

Please sign in to comment.