Skip to content

Commit 027c35c

Browse files
apapirovskiStephen Belanger
authored and
Stephen Belanger
committed
test: fix flaky test-http2-session-timeout
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: nodejs/node#15326 PR-URL: nodejs/node#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]>
1 parent fd2e292 commit 027c35c

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

test/parallel/test-http2-session-timeout.js test/sequential/test-http2-session-timeout.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@ if (!common.hasCrypto)
77
const h2 = require('http2');
88

99
const serverTimeout = common.platformTimeout(200);
10-
const callTimeout = common.platformTimeout(10);
10+
const callTimeout = common.platformTimeout(20);
11+
const minRuns = Math.ceil(serverTimeout / callTimeout) * 2;
12+
const mustNotCall = common.mustNotCall();
1113

1214
const server = h2.createServer();
1315
server.timeout = serverTimeout;
1416

1517
server.on('request', (req, res) => res.end());
16-
server.on('timeout', common.mustNotCall());
18+
server.on('timeout', mustNotCall);
1719

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

2123
const url = `http://localhost:${port}`;
2224
const client = h2.connect(url);
23-
makeReq(40);
25+
makeReq(minRuns);
2426

2527
function makeReq(attempts) {
2628
const request = client.request({
@@ -29,13 +31,17 @@ server.listen(0, common.mustCall(() => {
2931
':scheme': 'http',
3032
':authority': `localhost:${port}`,
3133
});
34+
request.resume();
3235
request.end();
3336

34-
if (attempts) {
35-
setTimeout(() => makeReq(attempts - 1), callTimeout);
36-
} else {
37-
server.close();
38-
client.destroy();
39-
}
37+
request.on('end', () => {
38+
if (attempts) {
39+
setTimeout(() => makeReq(attempts - 1), callTimeout);
40+
} else {
41+
server.removeListener('timeout', mustNotCall);
42+
client.destroy();
43+
server.close();
44+
}
45+
});
4046
}
4147
}));

0 commit comments

Comments
 (0)