Skip to content

Commit

Permalink
test: fix flaky test-http2-session-timeout
Browse files Browse the repository at this point in the history
Increase server timeout, reduce frequency of calls and
unbind timeout after runs are done in order to avoid
race conditions. Temporarily moved to sequential.

Fixes: #15326
PR-URL: #15338
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
apapirovski authored and jasnell committed Sep 20, 2017
1 parent 2ea2725 commit 1fbdf47
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ if (!common.hasCrypto)
const h2 = require('http2');

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

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

server.on('request', (req, res) => res.end());
server.on('timeout', common.mustNotCall());
server.on('timeout', mustNotCall);

server.listen(0, common.mustCall(() => {
const port = server.address().port;

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

function makeReq(attempts) {
const request = client.request({
Expand All @@ -29,13 +31,17 @@ server.listen(0, common.mustCall(() => {
':scheme': 'http',
':authority': `localhost:${port}`,
});
request.resume();
request.end();

if (attempts) {
setTimeout(() => makeReq(attempts - 1), callTimeout);
} else {
server.close();
client.destroy();
}
request.on('end', () => {
if (attempts) {
setTimeout(() => makeReq(attempts - 1), callTimeout);
} else {
server.removeListener('timeout', mustNotCall);
client.destroy();
server.close();
}
});
}
}));

0 comments on commit 1fbdf47

Please sign in to comment.