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: https://github.com/nodejs/node/pull/15688 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
d545c948c2
commit
a3cd8ed168
@ -3,18 +3,26 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
|
||||||
|
let time = Date.now();
|
||||||
|
let intervalWasInvoked = false;
|
||||||
|
const TIMEOUT = common.platformTimeout(200);
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
server.close();
|
server.close();
|
||||||
|
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.flushHeaders();
|
res.flushHeaders();
|
||||||
|
|
||||||
req.setTimeout(common.platformTimeout(200),
|
req.setTimeout(TIMEOUT, () => {
|
||||||
common.mustNotCall('Request timeout should not fire'));
|
if (!intervalWasInvoked)
|
||||||
|
return common.skip('interval was not invoked quickly enough for test');
|
||||||
|
common.fail('Request timeout should not fire');
|
||||||
|
});
|
||||||
|
|
||||||
req.resume();
|
req.resume();
|
||||||
req.once('end', common.mustCall(() => {
|
req.once('end', () => {
|
||||||
res.end();
|
res.end();
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(0, common.mustCall(() => {
|
server.listen(0, common.mustCall(() => {
|
||||||
@ -23,12 +31,19 @@ server.listen(0, common.mustCall(() => {
|
|||||||
method: 'POST'
|
method: 'POST'
|
||||||
}, (res) => {
|
}, (res) => {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
|
intervalWasInvoked = true;
|
||||||
|
// If machine is busy enough that the interval takes more than TIMEOUT ms
|
||||||
|
// to be invoked, skip the test.
|
||||||
|
const now = Date.now();
|
||||||
|
if (now - time > TIMEOUT)
|
||||||
|
return common.skip('interval is not invoked quickly enough for test');
|
||||||
|
time = now;
|
||||||
req.write('a');
|
req.write('a');
|
||||||
}, common.platformTimeout(25));
|
}, common.platformTimeout(25));
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
req.end();
|
req.end();
|
||||||
}, common.platformTimeout(200));
|
}, TIMEOUT);
|
||||||
});
|
});
|
||||||
req.write('.');
|
req.write('.');
|
||||||
}));
|
}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user