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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
apapirovski authored and mcollina committed Sep 18, 2017
1 parent a4e923f commit de51717
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 de51717

Please sign in to comment.