Skip to content

Commit e5f8b08

Browse files
TrottBethGriggs
authored andcommitted
test: improve reliability of http2-session-timeout
Check actual expired time rather than relying on a number of calls to setTimeout() in test-http2-session-timeout more robust. Backport-PR-URL: #22850 PR-URL: #20692 Fixes: #20628 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d1b7825 commit e5f8b08

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const h2 = require('http2');
77

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

1312
const server = h2.createServer();
@@ -21,9 +20,10 @@ server.listen(0, common.mustCall(() => {
2120

2221
const url = `http://localhost:${port}`;
2322
const client = h2.connect(url);
24-
makeReq(minRuns);
23+
const startTime = process.hrtime();
24+
makeReq();
2525

26-
function makeReq(attempts) {
26+
function makeReq() {
2727
const request = client.request({
2828
':path': '/foobar',
2929
':method': 'GET',
@@ -34,12 +34,14 @@ server.listen(0, common.mustCall(() => {
3434
request.end();
3535

3636
request.on('end', () => {
37-
if (attempts) {
38-
setTimeout(() => makeReq(attempts - 1), callTimeout);
37+
const diff = process.hrtime(startTime);
38+
const milliseconds = (diff[0] * 1e3 + diff[1] / 1e6);
39+
if (milliseconds < serverTimeout * 2) {
40+
setTimeout(makeReq, callTimeout);
3941
} else {
4042
server.removeListener('timeout', mustNotCall);
41-
client.close();
4243
server.close();
44+
client.close();
4345
}
4446
});
4547
}

0 commit comments

Comments
 (0)