test: skip test if host is too slow · nodejs/node@83a2513

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

}));