@@ -3,18 +3,26 @@
|
3 | 3 | const common = require('../common'); |
4 | 4 | const http = require('http'); |
5 | 5 | |
| 6 | +let time = Date.now(); |
| 7 | +let intervalWasInvoked = false; |
| 8 | +const TIMEOUT = common.platformTimeout(200); |
| 9 | + |
6 | 10 | const server = http.createServer((req, res) => { |
7 | 11 | server.close(); |
8 | 12 | |
9 | 13 | res.writeHead(200); |
10 | 14 | res.flushHeaders(); |
11 | 15 | |
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 | + |
14 | 22 | req.resume(); |
15 | | -req.once('end', common.mustCall(() => { |
| 23 | +req.once('end', () => { |
16 | 24 | res.end(); |
17 | | -})); |
| 25 | +}); |
18 | 26 | }); |
19 | 27 | |
20 | 28 | server.listen(0, common.mustCall(() => { |
@@ -23,12 +31,19 @@ server.listen(0, common.mustCall(() => {
|
23 | 31 | method: 'POST' |
24 | 32 | }, (res) => { |
25 | 33 | 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; |
26 | 41 | req.write('a'); |
27 | 42 | }, common.platformTimeout(25)); |
28 | 43 | setTimeout(() => { |
29 | 44 | clearInterval(interval); |
30 | 45 | req.end(); |
31 | | -}, common.platformTimeout(200)); |
| 46 | +}, TIMEOUT); |
32 | 47 | }); |
33 | 48 | req.write('.'); |
34 | 49 | })); |