diff options
author | Rich Trott <rtrott@gmail.com> | 2017-09-29 11:09:19 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2017-10-04 09:19:26 -0700 |
commit | a3cd8ed1681d39e9ce65b90f52ee6d67fc7d3fdc (patch) | |
tree | e9b6fae6a6b8740e2dd9172579526772d2af4980 /test/sequential/test-http-server-consumed-timeout.js | |
parent | d545c948c238f66cf673f156983b7c1b18b4bf28 (diff) | |
download | android-node-v8-a3cd8ed1681d39e9ce65b90f52ee6d67fc7d3fdc.tar.gz android-node-v8-a3cd8ed1681d39e9ce65b90f52ee6d67fc7d3fdc.tar.bz2 android-node-v8-a3cd8ed1681d39e9ce65b90f52ee6d67fc7d3fdc.zip |
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>
Diffstat (limited to 'test/sequential/test-http-server-consumed-timeout.js')
-rw-r--r-- | test/sequential/test-http-server-consumed-timeout.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/test/sequential/test-http-server-consumed-timeout.js b/test/sequential/test-http-server-consumed-timeout.js index e6157a0a1d..abe100c190 100644 --- a/test/sequential/test-http-server-consumed-timeout.js +++ b/test/sequential/test-http-server-consumed-timeout.js @@ -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(() => { @@ -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('.'); })); |