Skip to content

Commit 83a2513

Browse files
TrottMylesBorins
authored andcommitted
test: skip test if host is too slow
test-http-server-consumed-timeout will fail if the host is sufficiently loaded that a 25ms interval takes more than 200ms to be invoked. Skip the test in that situation. PR-URL: #15688 Fixes: #14312 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent ddee71a commit 83a2513

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33
const common = require('../common');
44
const http = require('http');
55

6+
let time = Date.now();
7+
let intervalWasInvoked = false;
8+
const TIMEOUT = common.platformTimeout(200);
9+
610
const server = http.createServer((req, res) => {
711
server.close();
812

913
res.writeHead(200);
1014
res.flushHeaders();
1115

12-
req.setTimeout(common.platformTimeout(200),
13-
common.mustNotCall('Request timeout should not fire'));
16+
req.setTimeout(TIMEOUT, () => {
17+
if (!intervalWasInvoked)
18+
return common.skip('interval was not invoked quickly enough for test');
19+
common.fail('Request timeout should not fire');
20+
});
21+
1422
req.resume();
15-
req.once('end', common.mustCall(() => {
23+
req.once('end', () => {
1624
res.end();
17-
}));
25+
});
1826
});
1927

2028
server.listen(0, common.mustCall(() => {
@@ -23,12 +31,19 @@ server.listen(0, common.mustCall(() => {
2331
method: 'POST'
2432
}, (res) => {
2533
const interval = setInterval(() => {
34+
intervalWasInvoked = true;
35+
// If machine is busy enough that the interval takes more than TIMEOUT ms
36+
// to be invoked, skip the test.
37+
const now = Date.now();
38+
if (now - time > TIMEOUT)
39+
return common.skip('interval is not invoked quickly enough for test');
40+
time = now;
2641
req.write('a');
2742
}, common.platformTimeout(25));
2843
setTimeout(() => {
2944
clearInterval(interval);
3045
req.end();
31-
}, common.platformTimeout(200));
46+
}, TIMEOUT);
3247
});
3348
req.write('.');
3449
}));

0 commit comments

Comments
 (0)