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 ecb902f

Browse filesBrowse files
Trottaddaleax
authored andcommitted
test: do not skip test-http-server-consumed-timeout
test-http-server-consumed-timeout has code to that causes it to be skipped on busy machines. Instead, use an exponential backoff for the timeout if the machine is busy. PR-URL: #30677 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 49458de commit ecb902f
Copy full SHA for ecb902f

File tree

Expand file treeCollapse file tree

1 file changed

+42
-41
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+42
-41
lines changed
Open diff view settings
Collapse file

‎test/sequential/test-http-server-consumed-timeout.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-http-server-consumed-timeout.js
+42-41Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,48 @@ const common = require('../common');
55
const assert = require('assert');
66
const http = require('http');
77

8-
let time = Date.now();
98
let intervalWasInvoked = false;
10-
const TIMEOUT = common.platformTimeout(200);
11-
12-
const server = http.createServer((req, res) => {
13-
server.close();
14-
15-
res.writeHead(200);
16-
res.flushHeaders();
17-
18-
req.setTimeout(TIMEOUT, () => {
19-
if (!intervalWasInvoked)
20-
return common.skip('interval was not invoked quickly enough for test');
21-
assert.fail('Request timeout should not fire');
9+
const TIMEOUT = common.platformTimeout(50);
10+
11+
runTest(TIMEOUT);
12+
13+
function runTest(timeoutDuration) {
14+
const server = http.createServer((req, res) => {
15+
server.close();
16+
17+
res.writeHead(200);
18+
res.flushHeaders();
19+
20+
req.setTimeout(timeoutDuration, () => {
21+
if (!intervalWasInvoked) {
22+
// Interval wasn't invoked, probably because the machine is busy with
23+
// other things. Try again with a longer timeout.
24+
console.error(`Retrying with timeout of ${timeoutDuration * 2}.`);
25+
return setImmediate(() => { runTest(timeoutDuration * 2); });
26+
}
27+
assert.fail('Request timeout should not fire');
28+
});
29+
30+
req.resume();
31+
req.once('end', () => {
32+
res.end();
33+
});
2234
});
2335

24-
req.resume();
25-
req.once('end', () => {
26-
res.end();
27-
});
28-
});
29-
30-
server.listen(0, common.mustCall(() => {
31-
const req = http.request({
32-
port: server.address().port,
33-
method: 'POST'
34-
}, () => {
35-
const interval = setInterval(() => {
36-
intervalWasInvoked = true;
37-
// If machine is busy enough that the interval takes more than TIMEOUT ms
38-
// to be invoked, skip the test.
39-
const now = Date.now();
40-
if (now - time > TIMEOUT)
41-
return common.skip('interval is not invoked quickly enough for test');
42-
time = now;
43-
req.write('a');
44-
}, common.platformTimeout(25));
45-
setTimeout(() => {
46-
clearInterval(interval);
47-
req.end();
48-
}, TIMEOUT);
49-
});
50-
req.write('.');
51-
}));
36+
server.listen(0, common.mustCall(() => {
37+
const req = http.request({
38+
port: server.address().port,
39+
method: 'POST'
40+
}, () => {
41+
const interval = setInterval(() => {
42+
intervalWasInvoked = true;
43+
req.write('a');
44+
}, common.platformTimeout(25));
45+
setTimeout(() => {
46+
clearInterval(interval);
47+
req.end();
48+
}, timeoutDuration);
49+
});
50+
req.write('.');
51+
}));
52+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.