diff options
author | Rich Trott <rtrott@gmail.com> | 2018-09-25 13:58:39 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-09-27 14:12:51 -0700 |
commit | 7603b4a693e67423eaa639aaa6e31fac8b8a04b8 (patch) | |
tree | bdfb44e8b5bb93ea77ef968fe1bf9d096f7a3b13 /test/sequential | |
parent | 83864b3bb0a18bf37548586c66be95be5843e640 (diff) | |
download | android-node-v8-7603b4a693e67423eaa639aaa6e31fac8b8a04b8.tar.gz android-node-v8-7603b4a693e67423eaa639aaa6e31fac8b8a04b8.tar.bz2 android-node-v8-7603b4a693e67423eaa639aaa6e31fac8b8a04b8.zip |
test: improve test-gc-http-client-connaborted
test-gc-http-client-connaborted is resource-intensive. It times out a
lot on CI. Move to sequential.
PR-URL: https://github.com/nodejs/node/pull/23091
Fixes: https://github.com/metadata
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'test/sequential')
-rw-r--r-- | test/sequential/test-gc-http-client-connaborted.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/sequential/test-gc-http-client-connaborted.js b/test/sequential/test-gc-http-client-connaborted.js new file mode 100644 index 0000000000..c043c474a6 --- /dev/null +++ b/test/sequential/test-gc-http-client-connaborted.js @@ -0,0 +1,60 @@ +'use strict'; +// Flags: --expose-gc +// just like test-gc-http-client.js, +// but aborting every connection that comes in. + +require('../common'); +const onGC = require('../common/ongc'); + +function serverHandler(req, res) { + res.connection.destroy(); +} + +const http = require('http'); +const todo = 500; +let done = 0; +let count = 0; +let countGC = 0; + +console.log(`We should do ${todo} requests`); + +const server = http.createServer(serverHandler); +server.listen(0, getall); + +function getall() { + if (count >= todo) + return; + + (function() { + function cb(res) { + done += 1; + } + + const req = http.get({ + hostname: 'localhost', + pathname: '/', + port: server.address().port + }, cb).on('error', cb); + + count++; + onGC(req, { ongc }); + })(); + + setImmediate(getall); +} + +for (let i = 0; i < 10; i++) + getall(); + +function ongc() { + countGC++; +} + +setInterval(status, 100).unref(); + +function status() { + global.gc(); + console.log('Done: %d/%d', done, todo); + console.log('Collected: %d/%d', countGC, count); + if (countGC === todo) server.close(); +} |