Skip to content

Commit

Permalink
test: improve reliability in http2-session-timeout
Browse files Browse the repository at this point in the history
Use `setImmediate()` instead of `setTimeout()` to improve robustness of
test-http2-session-timeout.

Fixes: nodejs#20628

PR-URL: nodejs#22026
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Jon Moss <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
Trott committed Aug 1, 2018
1 parent 9aebcc2 commit d2ffcac
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions test/sequential/test-http2-session-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const h2 = require('http2');
const http2 = require('http2');

const serverTimeout = common.platformTimeout(200);
const callTimeout = common.platformTimeout(20);
const mustNotCall = common.mustNotCall();

const server = h2.createServer();
const server = http2.createServer();
server.timeout = serverTimeout;

server.on('request', (req, res) => res.end());
Expand All @@ -19,7 +18,7 @@ server.listen(0, common.mustCall(() => {
const port = server.address().port;

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

Expand All @@ -37,7 +36,7 @@ server.listen(0, common.mustCall(() => {
const diff = process.hrtime(startTime);
const milliseconds = (diff[0] * 1e3 + diff[1] / 1e6);
if (milliseconds < serverTimeout * 2) {
setTimeout(makeReq, callTimeout);
setImmediate(makeReq);
} else {
server.removeListener('timeout', mustNotCall);
server.close();
Expand Down

0 comments on commit d2ffcac

Please sign in to comment.