Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: skip test if host is too slow #15688

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 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)
common.skip('interval was not invoked quickly enough for test');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return common.skip() as to not confuse static analysers

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,20 @@ 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();
console.log('diff is ' + (now - time));
if (time < now - TIMEOUT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I find now - time > TIMEOUT more intuitive

common.skip('interval is not invoked quickly enough for test');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return common.skip() as to not confuse static analysers

time = now;
req.write('a');
}, common.platformTimeout(25));
setTimeout(() => {
clearInterval(interval);
req.end();
}, common.platformTimeout(200));
}, TIMEOUT);
});
req.write('.');
}));