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.

Backport-PR-URL: #22850
PR-URL: #20692
Fixes: #20628
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and BethGriggs committed Oct 16, 2018
1 parent d1b7825 commit e5f8b08
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 e5f8b08

Please sign in to comment.