Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a4cbe30

Browse filesBrowse files
TrottMylesBorins
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. PR-URL: #20692 Fixes: #20628 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 56de3bf commit a4cbe30
Copy full SHA for a4cbe30

File tree

Expand file treeCollapse file tree

1 file changed

+8
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-6
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/sequential/test-http2-session-timeout.js
+8-6Lines changed: 8 additions & 6 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.