Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky test-http2-session-timeout #20692

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

@apapirovski apapirovski May 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm -1 on this change. process.hrtime isn't cheap so it's more — not less — likely to create situations where this test fails on slow platforms.

Actually, scratch that, I see what's making this more reliable.

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