Skip to content

Commit

Permalink
test: skip test if host is too slow
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Trott authored and MylesBorins committed Oct 17, 2017
1 parent 9be6221 commit 019fa6c
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions test/sequential/test-http-server-consumed-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,26 @@
const common = require('../common');
const http = require('http');

let time = Date.now();
let intervalWasInvoked = false;
const TIMEOUT = common.platformTimeout(200);

const server = http.createServer((req, res) => {
server.close();

res.writeHead(200);
res.flushHeaders();

req.setTimeout(common.platformTimeout(200),
common.mustNotCall('Request timeout should not fire'));
req.setTimeout(TIMEOUT, () => {
if (!intervalWasInvoked)
return common.skip('interval was not invoked quickly enough for test');
common.fail('Request timeout should not fire');
});

req.resume();
req.once('end', common.mustCall(() => {
req.once('end', () => {
res.end();
}));
});
});

server.listen(0, common.mustCall(() => {
Expand All @@ -23,12 +31,19 @@ server.listen(0, common.mustCall(() => {
method: 'POST'
}, (res) => {
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');
}, common.platformTimeout(25));
setTimeout(() => {
clearInterval(interval);
req.end();
}, common.platformTimeout(200));
}, TIMEOUT);
});
req.write('.');
}));

0 comments on commit 019fa6c

Please sign in to comment.